BASEL, Switzerland— Top-ranked Roger Federer lost his hometown tournament on Sunday, falling 6-4, 4-6, 6-2 to Novak Djokovic in the Swiss Indoors final.

Djokovic earned his fourth title of the season with a victory that ended Federer's run of three straight titles at the tournament where he was once a ballboy.

"It's disappointing to lose at home in the finals, no doubt," Federer said. "I thought I missed plenty of opportunities. I'm not looking for excuses. He played tough and he played well when he had to, and saved a ton of break points that were crucial."

Djokovic improved to 3-2 this year against Federer, and said the top-ranked Swiss pushed him to his limits.

"I have to produce something special to win," Djokovic said at sold-out St. Jakobshalle.

The second-seeded Serb clinched the first set by saving five break points in a game that lasted 24 minutes.

"It may be the longest I have ever played in my life," Djokovic said. "It was maybe the turning point in the whole match. I was fortunate to keep my nerves."

Federer fought back from a break down to win the second set and rouse his partisan fans, but Djokovic raced to a 4-0 lead in the decider and closed out the victory after Federer wasted three break points in the sixth game.

It was a tour-leading 71st win this year for Djokovic, who improved to 4-5 in finals in 2009. His other title wins were at Dubai, his home event at Belgrade, and Beijing last month.

Federer is 59-9 this year after losing only his third match since May.