You are not permitted to download, save or email this image. Visit image gallery to purchase the image.
In the 49th meeting between the two great rivals, the Swiss snapped a five-match losing run against Djokovic in London on Thursday and gained some consolation for his heartbreaking Wimbledon final defeat earlier this year.
After both men had been beaten by Dominic Thiem earlier in the group, their eagerly-anticipated duel was a straight shoot-out to join the Austrian in the semi-finals.
Cheered on by the majority of the 17,000 fans in the arena, Federer produced an astonishing display of power, grace and precision and Djokovic simply had no answer.
Djokovic's first defeat by Federer for four years means Rafael Nadal will end the year as world number one for the fifth time even if the Spaniard fails to reach the semi-finals.
Federer, Djokovic and Nadal have all achieved the feat five times. Pete Sampras managed it a record six times.
Nadal takes on Stefanos Tsitsipas in the other group on Friday and should he win and Alexander Zverev lose to Daniil Medvedev, it would set up a Nadal versus Federer semi-final.
Federer had played down talk of seeking revenge when asked about his impending clash with Djokovic this week, but his victory celebration showed exactly what it meant.
"I felt from the get-go I had good rhythm off the baseline and on the serve and that I felt like he was living dangerously if he was not going to play great tennis," Federer, who at 38 continues to mock the ageing process, told reporters.
"I got what I kind of expected, and it was a great feeling at the very end. The reaction showed."
Djokovic, who had needed to win the title to stand any chance of overhauling Nadal, said it had been a "bad match" from his side but admitted Federer had done everything right.
"He was the better player in all aspects," the 32-year-old said. "I have the utmost admiration for him. What he's still showing on the court is phenomenal."
Djokovic had reached the final on his last six appearances at the ATP's most exclusive event in London while six-time champion Federer had only once failed to reach the semi-finals in his 16 previous appearances.
Something had to give and from the moment second seed Djokovic double-faulted twice in the third game to invite an early break for Federer, he was never really in contention.
Federer was seeing the ball like a melon, timing his groundstrokes to perfection while his serve was unplayable.
He dropped only three points on serve in the opening set and Djokovic's only chance was that Federer would cool off.
Djokovic dug deep to fend off break points in the opening game of the second set, then had his one and only break point in the fourth game but Federer whipped a huge forehand into the corner before pouncing on a volley.
Federer was relentless and surged 0-40 ahead in the next game. Djokovic saved one break point with a backhand pass but hit a forehand long on the next.
With crowd roaring Federer on, the end came quickly.
Serving to stay in the match, Djokovic was broken to love as Federer sent a dipping backhand to his feet.
Earlier in the day, Matteo Berrettini became the first Italian to win a match at the ATP's year-ender, beating Thiem 7-6(3) 6-3. Despite the loss, Thiem won the group by virtue of his victory over Federer on Sunday.