Federer, who turns 35 in August, underwent knee surgery in February before missing May's French Open with a back problem, and the Swiss star said he was calling time on his 2016 season to focus on his recovery.
"I'm extremely disappointed to announce that I will not be able to represent Switzerland at the Olympic Games in Rio and that I will also miss the remainder of the season," Federer said on his Facebook page.
"I have made the very difficult decision to call an end to my 2016 season as I need more extensive rehabilitation following my knee surgery earlier this year.
"The doctors advised that if I want to play on the ATP World Tour injury free for another few years, as I intend to do, I must give both my knee and body the proper time to fully recover."
Federer, who suffered a heartbreaking five-set loss to Milos Raonic in the semi-finals at Wimbledon just over a fortnight ago, is enduring the toughest year of his career.
His injury-enforced absence at Roland Garros ended a streak of 65 successive Grand Slam appearances stretching back to 1999.
He has also failed to add to his 88 titles this year, his longest drought since 2000.
An Olympic singles gold medal is the lone major prize to escape Federer in his record-breaking career, having finished runner-up to Andy Murray at London 2012.
However, the former world number one insisted he would channel his focus on making a full recovery for next season, after recently announcing he would play in the Hopman Cup ahead of the Australian Open.
He added: "I am as motivated as ever and plan to put all my energy towards coming back strong, healthy and in shape to play attacking tennis in 2017."