"As many of you know, the past three years have presented me with challenges in the form of injuries and surgeries," Federer said in a post on Instagram.
"I've worked hard to return to full competitive form. But I also know my body's capacities and limits, and its message to me lately has been clear. I am 41 years old."
"I have played more than 1,500 matches over 24 years. Tennis has treated me more generously than I ever would have dreamt, and now I must recognize when it's time to end my competitive career.
"The Laver Cup next week in London will be my final ATP event. I will play more tennis in the future, of course, but just not in Grand Slams or on the tour," he added.
Federer, who dominated men's tennis after winning his first Grand Slam title at Wimbledon in 2003, has been troubled by injuries in recent years.
He has undergone three knee operations in the last two years and his last competitive match was a quarter-final defeat against Poland's Hubert Hurkacz at the 2021 Wimbledon.
Federer had announced he planned to return to the tour when he teams up with long-time rival and friend Rafa Nadal to play doubles at the Laver Cup in London.
He had also planned to play at the Swiss indoors tournament at home in Basel.