The experienced midfielder is set to continue his career at the Bundesliga champions after losing his starting berth at Madrid and will undergo a medical imminently
The Bundesliga champions were keen to add an extra midfielder to their squad due to the ongoing injury problems of players such as Javi Martinez, Bastian Schweinsteiger and Thiago Alcantara and they see the 32-year-old Alonso as a valuable addition.
The club were linked with a bid for Athletic Bilbao's Ander Iturraspe this week but have now confirmed it is Alonso who is poised to move to the Allianz Arena, subject to medical tests.
"It is correct that we have been in talks with Real Madrid and Xabi Alonso," Bayern executive board member Jan-Christian Dreesen said at a press conference.
"We have reached an agreement in principle. The player will arrive in Munich later on Thursday to undergo his medical."
Alonso signed a new contract with Real Madrid until the summer of 2016 earlier this year, but has lost his starting berth at the Santiago Bernabeu side this term as Carlo Ancelotti favours new signing Toni Kroos alongside Luka Modric and James Rodriguez in a three-man midfield.
The midfielder, who announced his decision to retire from Spain duty earlier this week, started his professional career with Real Sociedad and also played for Eibar and Liverpool before joining Madrid in the summer of 2009.
He had since made over 200 official appearances in all competitions for the Bernabeu outfit, but will now continue his career at Bayern.
Goal also understands that Madrid are eyeing a move for Wolfsburg midfielder Luiz Gustavo to replace Alonso in the Spanish capital.