Cannot play media. Sorry, this media is not available in your territory.
Video - Federer takes doubles gold
Roger Federer added an Olympic gold medal to his collection of tennis accolades by winning the men's doubles with Stanislas Wawrinka.
The Swiss pair beat Sweden's Thomas Johansson and Simon Aspelin 6-3 6-4 6-7 (4-7) 6-3 in the final in Beijing.
"It's a magical moment," said the 27-year-old Federer. "Something incredible in my career."
Bob and Mike Bryan of the United States took bronze, beating French pair Arnaud Clement and Michael Llodra 3-6 6-3 6-4.
The Bryans have won all four Grand Slam doubles titles but, like Federer, had not had any previous Olympic success.
Federer said he and his partner had managed to recover from their respective singles exits.
"It's incredible that we managed to stay on track to win in doubles," he said.
It has been a difficult year for the Swiss star, whose five-year reign as Wimbledon champion was ended by Rafael Nadal in July.
Federer will also be deposed world number one by the Spaniard on Monday after 236 weeks at the top.
Against Johansson and Aspelin, Federer's thumping groundstrokes and Wawrinka's impressive backhand gave the Swiss the early advantage.
After winning the first set, they soon broke to lead 3-1 in the second before the Swedes responded.
Federer looked less than comfortable at the net, although his volleying did later improve, while Wawrinka's serve came under severe pressure.
However, Johansson and Aspelin failed to take their chances and the Swiss went two sets up.
Federer switched service ends in order to serve again at the beginning of the third set, but a poor overhead and a wayward volley allowed their opponents to break him for the first time in the match.
The Swedes were still not firing on all cylinders themselves, however, and three double-faults by Aspelin meant the Swiss were able to break back.
It took a tie-break, which Johansson and Aspelin won, to decide the third set.
A brilliant reaction volley from Federer helped break Aspelin again at the start of the fourth set, Federer eventually serving out the match.
The 27-year-old, who has won 12 Grand Slam singles titles, celebrated victory by throwing up his hands and jumping up and down before embracing Wawrinka.