Madrid said the 24-year-old Kroos, a key member of Germany's World Cup-winning team, would be presented at the Santiago Bernabeu stadium later Thursday.
Neither Champions League winner Madrid nor Bundesliga champion Bayern disclosed the transfer fee.
Kroos was chosen as the best player at the 2007 Under-17 World Cup, when Germany finished third.
He joined Bayern when he was 16 and later spent 18 months on loan at Bayer Leverkusen before returning. He was a regular starter since Pep Guardiola took over as coach last season.
Kroos helped Bayern win the Champions League in 2013 and domestic doubles the past two seasons.
He was on Germany's 2010 World Cup squad, but was given a bigger role in coach Joachim Loew's team during qualifying for this year's tournament in Brazil.
Bayern chairman Karl-Heinz Rummenigge thanked Kroos for his time in Munich and wished him ''all the best in Madrid and at Real.''
- Sports & Recreation
- Toni Kroos
- Real Madrid
- Bayern Munich