The Austria international has agreed a five-year contract at the Bernabeu and will be presented at the club after Euro 2020.
Alaba arrives at Madrid with doubts over the future of both of the club's first-choice centre-backs.
Alaba made his first-team debut for Bayern in March 2010 and, except for a brief loan at Hoffenheim in 2010-11, has spent his entire professional career with the German giants.
He has been a key figure in one of Bayern's most successful teams, making more than 400 appearances for the club, winning two Champions League trophies -- including in 2020 -- 10 Bundesliga titles and six German Cups.
In November, Bayern confirmed that they would not be renewing Alaba's contract and were withdrawing their offer of an extension after it was rejected by the player and his representative.
The decision sparked a scramble for his signature among a number of top European clubs with Madrid, Barcelona, Paris Saint-Germain, Manchester United, Manchester City, Liverpool and Chelsea all linked.
Alaba confirmed his decision to leave Bayern in a news conference in February.
"It hasn't been an easy decision. I've been here for more than 13 years and I have the club in my heart," he said, admitting that "my Spanish isn't good" when asked about a possible move to La Liga.