Spain's double European champion Alonso, who also won last season's Champions League with Real, said in a news conference in Madrid that Bayern had provided him with a new challenge.
"It was a question of motivation and having finished a cycle," Alonso, who signed for Real in 2009 following a successful five-year stint at Liverpool, told reporters.
"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," he added.
"To be able to give 100 percent, I needed a new challenge if I am honest and I told this to the club."
The 32-year-old, who earlier this week announced his retirement from international soccer after winning one World Cup and two European championships with Spain, is seen as a replacement for the injured Bayern midfielder Javi Martinez.
"It is a sad day in one respect as I am finishing a fantastic five-year period where we have achieved great things but I think it is the right thing to do. It is the most difficult decision of my life," he said.
"My aim is to work hard and fight for all the trophies. The aims are the same as at Real Madrid, they have the same ambition and this is a new adventure for me," the player added.
Alonso passed a medical in Munich on Thursday with Bayern saying terms had also been agreed with the player, whom they wanted to sign as a straight transfer and not as a loan deal from the Spanish club as initially suggested.
Alonso will no doubt help orchestrate Bayern's game from his deep-lying position while also providing crucial leadership with holding midfielder Bastian Schweinsteiger and Thiago Alcantara also out injured.
The transfer of Alonso, who is Bayern's fifth Spanish player along with Pepe Reina, Juan Bernat, Thiago and Martinez, comes after the club signed Moroccan central defender Mehdi Benatia from AS Roma earlier this week.
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.
Bayern have been drawn with Manchester City, CSKA Moscow and Roma in the Champions League group stage.