It was Federer's first win over a top-four player since 2012, with Andy Murray having slipped down the rankings when he lost to the Swiss at the Australian Open.
Seventeen-times grand slam winner Federer predicted before the tournament that his best tennis was still to come, a suggestion that sounded far-fetched for a player who has slipped to eighth in the world, his lowest ranking since 2002.
From midway through the second set, however, the 32-year-old Swiss dominated Djokovic who is still some way short of his 2011 peak when he won Wimbledon, the U.S. Open and Australian Open.
"There was a buzz out there tonight. I was fully able to enjoy myself," Federer said in a courtside interview after setting up a final clash with Czech Tomas Berdych who beat German Philipp Kohlschreiber 7-5 7-5.
"It's never easy against Novak. Today I had a difficult start that put me on the back foot but the crowd kept pushing me on. It's a quick court and I'm always going to play aggressively."
Djokovic, 26, went into the match having won nine of his previous 12 encounters with Federer.
The Swiss, though, seized the opportunity to send a message to the tennis world that reports of his decline were premature.
"This is a big step in the right direction for me, gives me a lot of confidence," said Federer.
Such a statement looked unlikely in the first set as Federer netted to give Djokovic a 2-0 lead.
Serving for the set at 5-3, the Serb hit a lazy forehand into the net, shrugging his shoulders in disappointment as the capacity 5,000 crowd roared Federer's name.
That put the veteran 15-30 up but he then clubbed a simple forehand into the net.
Federer saved two set points, the second after a prolonged rally that ended with him whipping a delicious lob and rushing to the net for a volleyed winner.
But six-times grand slam champion Djokovic clinched the set with successive aces, rarely leaving the comfort of the baseline.
Serving at 2-2 in the second set, Federer's sliced forehand drifted agonisingly long to give his opponent a break point.
Such was Djokovic's dominance at that point that many in the crowd saw it as an effective match point and the Swiss rose to the occasion with a searing backhand pass.
"It's the stuff that sometimes decides matches and that's where you just need extra confidence or extra mental belief that you're going to win instead of losing," said Federer.
He held serve before breaking for a 4-2 lead in a rain-interrupted game - the players leaving the court for only a few minutes - with a backhand bullet from the baseline.
Five-times Dubai champion Federer secured the set with an ace as Djokovic's new coach Boris Becker looked on.
Earlier this week, the Serb said Becker's prime responsibility was to improve his mental toughness after having lost four grand slam finals, two to world number one Rafael Nadal and two to Britain's Andy Murray, in 15 months.
Djokovic's slide at the Aviation Stadium - he double-faulted in the first game of the final set to gift his opponent a crucial early break - implies his German coach has plenty of work to do.
"He played the second part of the match better, was more aggressive and played all round the court really well," said the world number two.
"I started making a lot of unforced errors in the second part of the second set, wasn't managing to move as well and he felt that was his opportunity."
Berdych's victory over Kohlschreiber was his 11th straight win and took him through to a second successive Dubai final.
- Sports & Recreation
- Roger Federer
- Novak Djokovic