The Czech Republic's leading player and third seed overcame the top-seeded Swiss hero 5-7 6-3 6-3 1-6 6-3 in an energy-sapping contest that lasted nearly three hours and was played in sweltering heat.
It was Novak's second title on the clay court in Gstaad, following his triumph two years ago.
"I did my best and I am disappointed not to win," said Federer, 21. "But after losing very quickly in the two finals I played in Basel, at least I went to five sets this time. Now I need a holiday and I am looking forward to next week."
After his magnificent performance on grass in last Sunday's Wimbledon final, it was understandable that Federer looked tired and, at times, care-worn as he battled a fresher opponent on a clay surface at altitude.
"My first thought is for Roger," said Novak. "He has done a fantastic job to play so well here after winning Wimbledon on grass. It is very difficult to do that. He has made a great effort."
He added: "Gstaad is a special place for me now. It was a great match and I kept fighting right through. I was a little better and a little luckier in the end."
Federer made a brisk start, serving with comprehensive precision and broke Novak in the sixth game. He led 5-2, but Novak broke back in the ninth and saved a break point in the 10th to make it 5-5. Although he was broken again to concede the set, it was a signal of what was to come.
LOOKING RAGGED
In the second and third sets, Federer's consistently immaculate service game deserted him and he began to look ragged.
Novak broke Federer three times in the second set, dropping his own serve only once, and broke him once more, in the fourth game of the third set when his own service was unbroken, to take the initiative.
The Swiss crowd, clapping and ringing cow bells, urged Federer to recover in the fourth set and he responded with an athletic return of a Novak smash as he discovered new reserves of energy.
He broke Novak to lead 2-0, held for 3-0, broke him again in the sixth for 5-1 and then served strongly again to take the set and level the match at two sets each.
It seemed another Swiss success, seven days after Wimbledon, was in the making, but Novak had other plans.
In the opening game of the fifth set, on Novak's serve, Federer forced two break points but failed to take either and the Czech hung on grimly through some lengthy rallies to take the lead.
Then, after four games with serve, he took advantage when Federer began to tire and he broke him to love to lead 4-2, held his own serve and after the Swiss held on at 5-3 down, he served out to love to take the match and the title.
"I did all I could, but it was not enough," said Federer. "His return of serve is one of the best out there on the tour and today he returned very hard.
"I wanted to win, but couldn't. It's a pity because I had a chance to win here and I didn't take it."
More from rediff