Brahim, who had six months remaining on his deal at City, joins the Madrid side in a move worth an initial £15.5m fee, with potential £6.5m add-ons.
The two European clubs have been in transfer talks over the 19-year-old in recent weeks and included what is effectively an anti-Manchester United clause in his contract.
Join Independent Minds
For exclusive articles, events and an advertising-free read for just
Get the best of The Independent
With an Independent Minds subscription for just
The deal includes a 15-per-cent sell-one fee, which rises to 40 per cent if United sign the youngster.
Brahim will complete a medical in Madrid on Monday and be presented at the Santiago Bernabeu stadium that afternoon before taking part in a press conference.
Pep Guardiola was reluctant to let the midfielder leave City, but with his contract expiring the club have opted to cash-in on the player that joined them from Malaga in 2013.
A Real Madrid club statement read: “Real Madrid C. F. and Manchester City have reached an agreement over the transfer of Brahim Díaz, who joins the club for the remainder of this season and the next six campaigns, until 30 June 2025.”
Brahim took to social media to thank Manchester City for their support as he bid goodbye to the club. “I was only a kid when I first came to England,” wrote Diaz. “They showed me the training ground at Platt Lane, I was told about the long term plans for the club and that day I trained as a Manchester City player for the first time in my life. I arrived to the city with my parents, Sufiel and Patricia, and my three sisters: Zaira, Idaira and Dunia. The fourth, Irina, was born a few months later. We couldn’t speak any English in my family.
“But language is not a problem in football.
“Today, I close a chapter of my life and I say goodbye to Manchester City, the club where I have grown. I came here being a kid and now I am a professional footballer.
“Thank you to all the managers in the club, from the academy to the first team, for believing in me because they taught me not only to be a better player, but a better person. Thank you to all the backroom staff and the medical services. Thank you to everyone involved in the offices working to make this club improve every day. Thank you to my teammates. And thank you, of course, to every single Manchester City supporter. I will never forget having my name chanted from the stands the night we beat Fulham in the League Cup.”