Bayern Munich midfielder Xabi Alonso will retire in the summer, the German champions have confirmed.

It had been reported earlier this year that former Spain international Alonso, 35, was planning to retire and he posted a message on Twitter on Thursday reading: "Lived it. Loved it. Farewell beautiful game."

Lived it. Loved it. Farewell beautiful game. pic.twitter.com/1aSN7GGNzZ - Xabi Alonso (@XabiAlonso) March 9, 2017

Bayern confirmed Alonso will retire in the summer shortly afterward, and the player told FC Bayern.tv live: "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."

One of the greats is saying goodbye. @XabiAlonso will retire from professional football at the end of the season. Danke, Xabi! �� #MiaSanMia pic.twitter.com/HrbdaUvC4e - FC Bayern English (@FCBayernEN) March 9, 2017

Bayern CEO Karl-Heinz Rummenigge added: "FC Bayern would like to thank a great player and person for representing FC Bayern to such a high standard both on and off the pitch.

"Xabi Alonso is one of the greats of world football. He has won everything there is to win during his career. He's a thoroughly remarkable person, and a gentleman of the game."

Bayern winger Franck Ribery had suggested this week that Renato Sanches could fill the void if Alonso retired.

"It's been a tough year for Renato," Ribery said. "Perhaps it will be easier for him next season, if Xabi Alonso isn't with us any longer."

Alonso began his career with Real Sociedad and moved to Liverpool in 2004, where he won trophies including the 2005 Champions League and 2006 FA Cup.

He left for Real Madrid in 2009, winning La Liga in 2011-12, the 2014 Champions League and the Copa del Rey on two occasions.

Xabi Alonso has won trophies including the 2010 World Cup and two Champions Leagues. Mike Hewitt - FIFA/FIFA via Getty Images

He joined Bayern in 2014 and won Bundesliga titles in his first two seasons as well as last season's DFB Pokal.

He has also enjoyed great success with Spain, winning the 2010 World Cup and the 2008 and 2012 European Championships before retiring from international football in 2014.

"I've experienced so much as a player with Real Sociedad, Liverpool, Real Madrid and Bayern Munich," Alonso said. "They are all great clubs. And of course, with the Spanish national team. I never would've thought I'd have such a great career, and I hope there's more to come before it ends."

Bayern are currently top of the Bundesliga and remain in contention for the DFB Pokal and Champions League this season.