(CNN) -- Faced by a man wielding a tennis racquet like a wand, Novak Djokovic produced some magic of his own to claim victory in the final of the Indian Well Masters event.
Djokovic, who was blown away in the opening set by Roger Federer, was forced to summon every ounce of strength and determination to deny his opponent a fifth title at the Californian venue.
Having lost the opener 6-3, Djokovic hit back to take the second 6-3 and win a third set tiebreak following an enthralling contest.
It was Djokovic's third triumph at Indian Wells having won there in 2008 and 2011 and his first tournament victory of the year.
Federer, the man so many dared to write off, showed once again that he still possesses enough magic to trouble his younger opponents.
The 17-time grand slam champion had begun in imperious fashion, racing through the first set as Djokovic struggled for rhythm and consistency.
Federer, 32, defeated Djokovic on his way to winning the Dubai title last month and his confidence was clear to see as he wasted little time in dominating his opponent.
The Serb improved in the second set, probing away at Federer at every opportunity, gaining his first break point in the eighth game.
And the six-time grand slam winner duly obliged, taking the second of the break points afforded to him to move 5-3 ahead.
Djokovic then held his nerve, serving out the game to 30 to level at one set all and take the second 6-3.
The World No.2 then had the opportunity to take control of the final set but failed to convert a break point in the opening game.
Djokovic continued to put the pressure on the Federer serve and earned another break point in the third game -- but once again his opponent shut the door with a stunning forehand.
But with Federer beginning to toil, Djokovic finally gained the break point he had so badly craved to move into a 2-1 lead.
The contest continued to go with serve -- leaving Djokovic to serve it out at 5-4.
It appeared for all the world that the he would simply go through the motions after becoming so dominant.
But Federer, defiant until the last, took the first three points to move to 0-40 on the Djokovic serve.
And the Swiss leveled at 5-5, taking the second of those break points to breathe new life into the contest before holding serve to love to move 6-5 ahead.
Djokovic held his nerve to take the final set to a tiebreak with the crowd willing on both players following a pulsating contest.
With both players having given everything, it was Djokovic who made the first significant breakthrough, moving into a 5-1 lead.
Federer fought back to trail 3-6 but Djokovic finally prevailed, taking the tiebreak 7-3.
In the women's event, Italy's Flavia Pennetta defeated World No.3 Agnieszka Radwanska 6-2, 6-1 to win the biggest title of her career.
Pennetta, 32, had already seen off top seed Li Na of China as well as former U.S. Open champion Samantha Stosur.
Radwanksa, seeded second, struggled throughout with an injury to her left leg and succumbed after an hour and 13 minutes.
Pennetta had considered retiring from tennis before reaching the semifinals of last year's U.S. Open.
Her decision to continue playing appears a wise one following her latest triumph.
"Last year exactly in this tournament I was thinking 'Oh my god, I can't play anymore," a beaming Pennetta she told reporters. "Now I am here with the trophy."
Pennetta, who had not won a WTA event since Marcella in 2010, has now won 10 titles.
"The first set was I think pretty good," Pennetta said. "I tried to go for winners.
"Second set, I see she has a physical problem and I started thinking too much."