The 35-year-old confirmed the news, which had been rumoured for the last two months, on social media on Thursday morning.
Alonso came through the ranks at Real Sociedad before joining Liverpool in 2004, where his first season culminated in the miraculous Istanbul comeback against AC Milan that secured a Champions League trophy.
He also won an FA Cup, a UEFA Super Cup and a Community Shield with the Reds and was at Anfield until 2009, when he moved on to Real Madrid,
More silverware, including a second Champions League and a La Liga title, came while he was at the Bernabeu
A move to Bayern followed in 2014 and Alonso helped the club claim Bundesliga titles in his first two seasons – they are also seven points clear this season and reached the Champions League quarter-finals by completing a 10-2 win over Arsenal on Tuesday.
He also won a World Cup and two European Championships while playing for Spain, for whom he won 114 caps and scored 16 goals.
Alonso said: “It wasn’t an easy decision to make, but I believe it’s the right time.
“I always thought it would be better to quit sooner rather than later. I still feel good, but I believe this is the right moment.
“I wanted to end my career still at the highest level, and Bayern is the highest level. I’m incredibly proud and happy to play for FC Bayern and to be a part of this family