Xavi Hernandez spent the majority of his storied career at Barcelona. Photo by Miguel Ruiz/FC Barcelona via Getty Images

Barcelona and Spain legend Xavi Hernandez has announced that he will retire from football after 21 years.

The Spanish national team veteran, who plays in Qatar for Al Sadd, confirmed in an open letter on Thursday that this will be his last season and that he will continue his career as a coach.

"It has been a privilege to play football up to age 39 and I would like to finish out the season on the top by winning the Amir Cup and reaching the next stage of the Asian Champions League.

"This is my last season as a player, but I really want to see what the future holds for me as a manager," Xavi, who joined Barca's senior side during the 1998-99 season, said in the letter.

The Barcelona academy product led the Catalan club to eight titles in La Liga as well as four Champions League trophies. His total silverware for club and country, 31 trophies, is a number only surpassed by his longtime Spain and Barcelona teammate Andres Iniesta.

He spoke about his developing style as a manager, citing the influence of Johan Cruyff and La Masia and the style that Barcelona gave to the world.

"I love to see teams that take the lead on the pitch, that attacking football and that return to the essence that we all know from the days of our youth, possession of the ball," he said.

"It has been a privilege to accomplish what I have done over the past two decades. And that is why I feel that it is my duty to begin an initiative on the field and give back to football as long as I am able."

Capped 113 times for Spain, Xavi played a key role in his country's 2010 World Cup victory in addition to Spain's victories at both Euro 2008 and Euro 2012. He retired from national team play in 2014.