The 32-year-old midfielder, who on Wednesday announced his retirement from international soccer after winning one World Cup and two European championships with Spain, is considered as a replacement for the injured Javi Martinez.
He can help orchestrate Bayern's game from his deep-lying position while also providing leadership with holding midfielder Bastian Schweinsteiger and Thiago Alcantara both out injured.
Bayern finance chief Jan-Christian Dreesen and Matthias Sammer told reporters terms had "basically" been agreed and the player would arrive later on Thursday for a medical.
"We have basically agreed terms with Xabi Alonso. He will arrive today for his medical," Dreesen said. "We are in friendly talks with Real and am confident that in one or two days there will be agreement with Real as well."
He said, however, Bayern were eager to sign him rather than take him on loan with Alonso's contract running out in 2016.
The transfer of Alonso, who will be Bayern's fifth Spanish player along with Pepe Reina, Juan Bernat, Thiago Alcantara and Martinez, comes just one day after the club signed central defender Mehdi Benatia from AS Roma for a reported 25 million euros ($33.02 million).
"This is purely sporting decision because Alonso can instantly help us and boost our quality," Bayern sports director Matthias Sammer said. "He can play top level football for at least two more years."
Martinez has been ruled out for at least six months with a cruciate ligament tear, forcing fellow Spaniard, coach Pep Guardiola, to look for more defensive midfield options.