The Swiss was conclusively beaten 6-2 6-1 6-4 in a repeat of last month's Wimbledon final, which he won.
"He played very well. He was better, much better than I was today. Still, I'm happy with silver," Federer told BBC Sport.
"Maybe there was an emotional drain out there but I didn't think that I played too badly.
"It's unfortunate but it's still a great day for me."
Federer's defeat means that he has missed out on the opportunity to win the prestigious Career Golden Slam - all four Slams and an Olympic gold medal in the singles competition.