The 39-year-old, who currently plays for Qatari club Al Sadd SC, won eight La Liga titles and four Champions League trophies while at Barcelona, BBC Sport reported.
The 2010 World Cup winner will now become a coach, adding he is excited to see "what the future holds".
"What I have achieved in the last two decades has been a privilege," he said.
"Therefore, I believe it is my duty to take the initiative of the field and return through football whenever possible."
In a statement released to Spanish news outlet AS, he added, "My philosophy as a coach reflects the style we developed for many years under the influence of Johan Cruyff and La Masia, and that has its greatest exponent in the way of playing football in Barcelona.
"I love seeing the teams take the initiative in the field, attack football and return to the essence of what we all love from our childhood days: Possession football."
The midfielder – who scored 13 goals in 133 appearances for Spain – left Barcelona in 2015 and joined Al Sadd on a three-year contract.
He will continue his work with Generation Amazing, a Qatari program created "to ensure the 2022 World Cup leaves a human and social legacy".
"During the next four weeks, I will tie my boots to play the last matches of an unforgettable race that has lasted for 21 years and has taken me all over the world," Xavi said.
"It has been a privilege to play football until I was 39 years old."
Former Barca and Spain teammate Andres Iniesta tweeted, "The best partner. A privilege to grow and share at your side all my career and the best moments. An example of a professional. Thank you for everything you've taught the world of football."