Roger Federer, a 20-time Grand Slam singles champion, will retire from top-level tennis after the Laver Cup in London later this month.
Swiss Federer, 41, has not played since Wimbledon 2021, after which he had a third knee operation.
"My body's message to me lately has been clear," Federer 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.
Roger Federer wins Australian Open in 2018
Federer's last Grand Slam victory was at the 2018 Australian Open
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.
His 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.
BDST: 2026 HRS, SEP 15, 2022