The 32-year-old former Liverpool player, who won last season's Champions League trophy with Real, said in a news conference in Madrid that Bayern had provided him with a new challenge.
Alonso said: "When Bayern are interested in you then you must not hesitate for a single second. I am looking forward to what lies ahead. I am proud at my age to have another chance to play for such a great club.
"It was a question of motivation and having finished a cycle.
"We achieved the goal of everyone to win the 'Decima' (10th European Cup victory) last season and I think in many ways that ended a cycle and it is the time to start afresh.
"To be able to give 100 percent, I needed a new challenge if I am honest and I told this to the club."
The Bavarian giants signed Alonso following injuries to Thiago Alcantara, Bastian Schweinsteiger and Javi Martinez, who ruptured his cruciate knee ligament in the Super Cup defeat against Borussia Dortmund.
Alonso will join Moroccan defender Mehdi Benatia, who arrived at Bayern earlier this week from Roma for a reported €30m fee.
Spain midfielder Alonso was deemed surplus to requirements in the Spanish capital following the arrival of Germany international Toni Kroos from Bayern.
Alonso announced his retirement from international soccer earlier this week after winning one World Cup and two European Championships with Spain.