Roger Federer, one of the greatest players of all time, will retire from top-level tennis after the Laver Cup in London this month.
The 20-time Grand Slam champion has not played since Wimbledon 2021, after which he had a third knee operation.
“My body’s message to me lately has been clear,” Swiss Federer, 41, said.
“I have played more than 1,500 matches over 24 years. Now I must recognise when it is time to end my competitive career.”
He added: “To the game of tennis, I love you and will never leave you.”
Federer has struggled with a knee problem for the past three years that has restricted him to only three of the 11 Grand Slams staged since the start of 2020.
He has not played a competitive match since losing to Hubert Hurkacz in the quarter-finals at Wimbledon last summer.
He subsequently announced he needed more surgery on his knee having previously had two operations in 2020.
Only Spain’s Rafael Nadal, with 22 majors, and Serbia’s Novak Djokovic, with 21, have more men’s Grand Slam singles titles than Federer.
“This is a bittersweet decision because I will miss everything the tour has given me,” added Federer.
“But, at the same time, there is so much to celebrate. I consider myself one of the most fortunate people on Earth. I was given a special talent to play tennis and I did it at a level that I never imagined for much longer than I ever thought possible.”
As well as thanking his family, support team and fans, Federer also thanked his opponents from a golden era of the men’s game.
“I was lucky enough to play so many epic matches that I will never forget. We battled fairly, with passion and intensity, and I always tried my best to respect the history of the game.
“I feel extremely grateful. We pushed each other, and together we took tennis to new levels.”
Federer made his professional debut aged 16 in 1998 and won his first Grand Slam title at Wimbledon in 2003.
He ends his career with a record total of eight men’s singles victories at the All England Club.
Federer’s final Grand Slam triumph came at the 2018 Australian Open when, aged 36, he became the second-oldest man to win a major singles title in the Open era.
After rising to world number one for the first time in 2004, he spent 310 weeks as the leading player on the ATP Tour during his career – a record until he was surpassed by Djokovic in February 2021.
He won Olympics doubles gold for Switzerland alongside Stan Wawrinka at Beijing 2008 and singles silver at London 2012 when Britain’s Andy Murray reversed his Wimbledon final defeat from the previous month.
He was also part of the Swiss team that won the Davis Cup for the first time in 2014 and lifted a record six ATP Finals titles.
The three-day Laver Cup, staged at the O2 Arena in Greenwich, begins on Friday, 23 September.
Federer is due to join Murray, Nadal, Djokovic, Greece’s Stefanos Tsitsipas and Norway’s Casper Ruud in a Europe team taking on a team representing the rest of the world.
He was part of the group that created and organised the tournament, first held in 2017.
Federer’s retirement announcement comes less than two weeks after 23-time Grand Slam singles champion Serena Williams played what is expected to be the final match of her career at the US Open.
Where Federer won his Grand Slam titles
Federer is the most successful grass-court male player of all-time on the back of his unparalleled Wimbledon success, with his last triumph at the All England Club coming in 2017.
The Australian Open was the next most successful major tournament for the Swiss, winning six titles at Melbourne Park between 2004 and 2018.
He claimed all five of his US Open titles in a row between 2004 and 2008, while his one and only triumph on the French Open clay came in 2009.
Federer reached 31 Grand Slam finals in total, doing so for the last time at Wimbledon in 2019 when he lost to Djokovic having held two championship points.
Federer retires – reaction
The chairman of the All England Lawn Tennis Club, Ian Hewitt, congratulated Federer on a “truly remarkable career”.
“He will forever be celebrated as one of our greatest Wimbledon champions, having lifted the trophy eight times from his 22 appearances at the All England Club,” Hewitt added.
“I hope that, in retirement, Roger can look back with enormous satisfaction and pride on all his accomplishments and the high esteem in which he is held by the tennis community.”
Argentina’s Juan Martin del Potro, who defeated Federer to win the 2009 US Open, paid fulsome tribute to his rival.
“I love you Roger,” he tweeted.
“Thank you for everything you’ve done in tennis and with myself. Tennis world will never be the same without you.”
ATP chairman Andrea Gaudenzi said: “He spearheaded an incredible new era of growth and elevated the popularity of our sport. Few athletes have transcended their field in such a manner.”
Lawn Tennis Association chief executive Scott Lloyd said: “Nobody who saw him play will forget his grace, elegance and poise on court.”
Russell Fuller, BBC tennis correspondent
We will, of course, remember those 20 Grand Slam titles, and those 237 weeks in a row as the world number one.
We will also remember Federer for his movement, his forehand and his serve.
But he will be remembered most of all for the elegance with which he played the sport he loved: a style and grace which endeared him to so many.
We had been dreaming of the prospect of Federer making a comeback at the age of 41.
Illogical, probably, after four knee operations. But such mesmeric gifts leave little room for logic.
Wimbledon, or his home town of Basel – where, as a ballboy, his passion for professional tennis was stirred – would have been perfect places to say farewell.
But at least in London next week he will have the company of Rafael Nadal, Novak Djokovic and Andy Murray: rivalries that have further enriched his career.