"I've been doing a lot of checks with the doctors, as well, on my knee, getting all the information as I hurt myself further during the grass-court season and Wimbledon," the 40-year-old said in an Instagram post Sunday.
"Unfortunately, they told me for the medium to long-term, to feel better, I will need surgery, so I decided to do it. I will be on crutches for many weeks and then also out of the game for many months."
Federer, who is tied with Rafael Nadal and Novak Djokovic on 20 career grand slams, was noncommittal about his future in tennis.
"I want to be healthy. I want to be running around later, as well, again, and I want to give myself a glimmer of hope, also, to return to the tour in some shape or form," he added.
"I am realistic, don't get me wrong. I know how difficult it is at this age right now to do another surgery and try it."
Federer missed more than a year of action after having two operations on his knee after the Australian Open in 2020.
He returned for the 2021 French Open but withdrew after his third-round win to protect his knee. Federer then lost in the quarterfinals at Wimbledon in June.
After his Wimbledon loss, he withdrew from the Tokyo Olympics after announcing an injury setback with his knee.
This year's US Open is scheduled to start on August 30 and runs through September 12 in New York.
He underwent arthroscopic surgeries on his right knee in February and May 2020, skipping the two remaining majors during a pandemic-scrambled season to recover. He also sat out the 2021 Australian Open for the same reason — to ensure he was fully recovered and as prepared as possible to contend for a ninth Wimbledon championship.
But he suffered a straight-sets, quarterfinal loss to 14th-seeded Hubert Hurkacz, failing to win a single game in the final set. He has not played since.
In his Instagram announcement Sunday, Federer said: “I am realistic; don’t get me wrong. I know how difficult it is at this age right now to do another surgery and try it. But I want to be healthy. I will go through the rehab process, I think, also with a goal while I’m still active, which I think is going to help me during this long period of time.”
Rafael Nadal vows to regain form after losing at Citi Open
Nadal took roughly two months off after his grueling, four-sets semifinal loss at the French Open in June to address a debilitating injury to his left foot. After skipping Wimbledon and the Tokyo Olympics, he returned to competition at Washington’s Citi Open but lost in his second match, hampered by the foot injury.
Nadal then traveled to the Masters 1000 event in Toronto, which is typically essential preparation for top players in the run-up to the U.S. Open, but withdrew shortly before his first match, explaining that his foot needed further attention. He also announced he wouldn’t compete the following week in Cincinnati.
Djokovic withdrew from the Toronto and Cincinnati events a week earlier, citing the need to recover before the U.S. Open.
Djokovic, who has won the first three majors of the season to draw even with Federer and Nadal, had been seeking to become the first man to claim a “Golden Slam” — winning all four majors and Olympic singles gold in the same year. But his bid was derailed by a semifinal loss in Tokyo. He has not competed since.