Alaba will arrive in the Spanish capital as a free agent, with his contract at Bayern Munich expiring this summer.
The Austria international announced in February that he will be leaving the Bavarians at the end of the 2020/2021 season after 13 years at the club.
Alaba joined Bayern Munich’s youth system in 2008 and made 431 appearances in total for the club, scoring 33 goals.
The 28-year-old has shown his versatility in recent seasons as he switched from his usual left back position to the centre of defence in his latter days with Bayern Munich and can operate in midfield too.
"Real Madrid C. F. has reached an agreement with David Alaba for the player to join the club for the next five seasons. David Alaba will be unveiled as a new Real Madrid player after the end of the 2021 European Championship," a statement from Los Blancos read.
In a short message on Twitter, Alaba wrote: "I leave a special club for another special club. I am really happy and honored to join Real Madrid. After so many years in Munich, I will face a new challenge and I will give my best to continue the club's special history."
Alaba won ten Bundesliga titles with the Bavarians, two UEFA Champions League trophies, six DFB-Pokals, two FIFA Club World Cups among numerous other honours.