Since he won his first major at Wimbledon in 2003, Federer has been among a trio of dominant players who have regularly topped the rankings for much of this century — him, Rafael Nadal and Novak Djokovic.
Nadal has won 22 Grand Slam singles titles, and Djokovic has 21 major trophies on his mantel.
"Tennis has treated me more generously than I ever would have dreamt, and now I must recognize when it is time to end my competitive career," Federer, 41, said in an audio message on social media.
He said his final competitive matches will be at the Laver Cup in London starting Sept. 23.
"This is a bittersweet decision, because I will miss everything the tour has given me. But at the same time, there is so much to celebrate," he continued.
"I consider myself one of the most fortunate people on Earth."
Federer, whose last Grand Slam win was at the 2018 Australian Open, said injuries and age have finally taken their toll.
"I've worked hard to return to full competitive form," he said. "But I also know my body's capacities and limits, and its message to me lately has been clear. "
Federer said he'll still pick up a racket in the years to come, but not in any major competitions.
"I will play more tennis in the future, of course, but just not in Grand Slams or on the tour," he said.
Federer’s announcement comes nearly two weeks after women’s tennis legend Serena Williams was eliminated from the U.S. Open, most likely marking the end of her storied career of 23 Grand Slam singles titles.
The Laver Cup is a team competition, and Federer will be on Team Europe, a side that includes fellow legends Nadal and Djokovic, the other two-thirds of tennis’ Big Three.
Federer will end his career with 103 Association of Tennis Professionals singles titles, his last one at the 2019 Swiss Indoors in his hometown, Basel.
"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," Federer said.
Federer thanked his wife, parents, sister, four children, support staff and sponsors for being by his side for 24 seasons on tour.
Federer's prowess on the court was matched only by his big-money wins outside the lines as one of tennis' most sought-after advertising figures.
Even in the twilight of his career, Forbes this year ranked him as the world's seventh-highest-paid athlete. His name and face have been on high-end apparel, cars, watches and chocolates.
"I would like to thank my loyal sponsors, who have really been like partners to me," Federer said.
He also shouted out fans, who made him one of the biggest draws on the tour. Tennis enthusiasts sporting merchandise with Federer’s stylized “RF” logo have long filled the stands.
“You will never know how much strength and belief you have given me,” he said to his fans.
“The inspiring feeling of walking into full stadiums and arenas has been one of the huge thrills in my life. Without you, those successes would’ve felt lonely, rather than filled with joy and energy."