The 24-year-old played in all of his country’s matches in the World Cup in Brazil, as Germany claimed the trophy for the fourth time.
Kroos won three Bundesliga titles in four seasons with Bayern, clinching the DFB-Pokal three times and being part of the side which won a historic treble in 2013.
That success included the Champions League, before Bayern won the UEFA Super Cup and FIFA Club World Cup last season.
The midfielder joins compatriot Sami Khedira in Madrid and will be presented to the media later on Thursday after undergoing a medical.
"We would like to thank Toni Kroos for his time here in Munich," said Bayern chairman Karl-Heinz Rummenigge.
"We enjoyed great success here together. We would like to wish him and his family all the best in Madrid and with Real."
F**k you Toni! You broke my heart. Don't be coming round here no more, with your beautiful blond hair, and your sexy cross-field passes.- GVMUFC