Alonso was to have a medical in Munich on Thursday while Bayern finalise the deal with Real with whom Alonso is under contract until 2016, the German club said.
The move comes after Alonso on Wednesday announced his retirement from international football.
The 32-year-old was a key member of the Spanish sides that won European Championships in 2008 and 2012, as well as their first World Cup in 2010.
However, Alonso’s final international tournament ended in catastrophe as the holders crashed out of the World Cup in Brazil in the group stage following defeats to the Netherlands and Chile.
At Bayern he will link up with former Barcelona coach Pep Guardiola who has endured a difficult start to the season with injuries to Javi Martinez, Bastian Schweinsteiger, Rafinha and Thiago Alcantara.
He also lost central midfielder Toni Kroos in the close season, the German international going to Real Madrid.
The injuries saw Bayern bolster their defensive options on Wednesday by signing Moroccan international full-back Mehdi Benatia on a five year deal from Italian Serie A side Roma.
Bayern began the new Bundesliga season with a 2-1 win against Wolfsburg. They travel to Schalke this Saturday.