“I will be on crutches for many weeks and out of the game for many months,” 20-time Grand Slam title winner Federer said in a video posted on his Instagram account.
The decision immediately rules him out of the US Open, where he has been champion five times and which starts in two weeks’ time.
“I want to give myself a glimmer of hope to return to the tour in some shape or form,” added Federer.
“I am realistic, don’t get me wrong. I know how difficult it is at my age to go through another surgery. I will try it. I want to be healthy, I want to be running around.”
Federer, who has played just 13 matches in 2021, underwent two knee surgeries in 2020 when he played only six times.
He had already pulled out of the Tokyo Olympics to rest his knee.
Federer withdrew from this year’s French Open after reaching the fourth round and was knocked out in the quarter-finals of Wimbledon, a tame 6-3, 7-6 (7/4), 6-0 loss to Poland’s Hubert Hurkacz.
That defeat was only his 14th at the All England Club in 119 matches, and the first time he had been beaten in the tournament in straight sets since a first-round exit at the hands of Mario Ancic in 2002.
It was also the first time he had lost a set 6-0 at Wimbledon and just the third time at a Slam.
“I’ve been doing a lot of checks with the doctors on my knee,” he added on Sunday.
“I hurt myself further during the grass-court season and it’s just not the way to go forward.
“They told me to feel better I’ll need surgery. I decided to do it.”
After turning 40 last weekend, Federer said he was learning to adjust to the fact that recovering from niggles takes two weeks rather than two days.
“It was different before. The questions were simple: what is my place in the ranking? What will my next tournament be?”, he told Blick newspaper.
“Today, it’s more difficult: how do I feel when I start training again? What are my goals? How to reconcile all this with the family? What does the rest of the team say?
“I am much more enthusiastic than before, the attitude is different. It’s really completely different from 10 years ago.”
Federer captured his most recent major at the 2018 Australian Open.
He was already well past 36 and the second oldest man to clinch a Slam title
Since then, Novak Djokovic has claimed eight more majors and old rival Rafael Nadal has picked up four.
Both now stand level on 20 Slams with Federer.
Should Federer be preparing to bow out after 23 years on tour, he will leave behind a career decorated by 103 titles — only Jimmy Connors with 109 has more — a combined 310 weeks at number one and more than $130 million in prize money alone.
Later Sunday, the US Open confirmed Federer’s withdrawal from the final Grand Slam event of the year with his spot in the draw taken by Tallon Griekspoor of the Netherlands.
Nadal remains a doubt for the US Open where he is a four-time champion.
The 35-year-old Spaniard suffered a foot injury in his semi-final loss to Djokovic at the French Open in June.
The Spaniard skipped Wimbledon and the Olympics and played just one match in Washington earlier this month before withdrawing from the Toronto and Cincinnati Masters events.
Djokovic is also skipping Cincinnati after his disappointing Olympics campaign.
The field, headed by Russian Daniil Medvedev, is without resting world number one Novak Djokovic plus injured Rafael Nadal and Roger Federer.
“Things are changing. Bodies are breaking down instead of top players being overtaken by tennis (progress),” said three-time major winner Andy Murray in Cincinnati on Sunday.