Roger Federer will not participate in the Tokyo Olympics, writing on social media Tuesday that he "experienced a setback" with his knee during the grass-court season.

Federer had said before Wimbledon that he would make a decision about going to the Summer Games after the Grand Slam tournament ended.

The 39-year-old from Switzerland lost in the quarterfinals at the All England Club last week to Hubert Hurkacz.

CLICK HERE FOR MORE SPORTS COVERAGE ON FOXNEWS.COM

Federer had two operations on his right knee in 2020 and went more than a full year between matches. He returned to Grand Slam action at the French Open and then pulled out of that tournament after three victories, saying he wanted to be rested and ready for the grass circuit — especially Wimbledon.

On Tuesday, he said in a post on Twitter that because of the setback, he has "accepted that I must withdraw from the Tokyo Olympic Games. I am greatly disappointed, as it has been an honor and highlight of my career each time I have represented Switzerland."

Federer won a gold medal alongside Stan Wawrinka in doubles at the 2008 Beijing Olympics and a silver in singles at the 2012 London Olympics, losing to Britain's Andy Murray in the final at the All England Club.

Federer sat out the 2016 Rio de Janeiro Games because of problems with his left knee.

"I have already begun rehabilitation in the hopes of returning to the tour later this summer," wrote Federer, who turns 40 on Aug. 8.

The U.S. Open, the year's last Grand Slam tournament, is scheduled to begin Aug. 30 in New York.

Federer joins a growing list of tennis stars who are not going to Tokyo, where COVID-19 cases have been rising as the July 23 opening ceremony approaches.

Serena Williams, Rafael Nadal, Simona Halep, Dominic Thiem and Nick Kyrgios are among the players who will not be competing for medals.

Novak Djokovic, who tied Federer and Nadal for the men's record by winning his 20th major championship at Wimbledon on Sunday, said after the final that he was 50-50 on whether to go to the Games.

CLICK HERE TO GET THE FOX NEWS APP

On the eve of Wimbledon's start, Federer was asked where things stood for him on Tokyo.

"My feeling is I would like to go to the Olympics. I would like to play as many tournaments as possible. But I think we decided now, let’s just get through Wimbledon, sit down as a team, and then decide where we go from there," he said then. "I wish I could tell you more. In previous years, it was definitely easier. At the moment, things are not as simple as in the past. With age, you have to be more selective. You can’t play it all."