The Swiss started the tournament with a chastening straight-sets defeat to Dominic Thiem but found his best form when it mattered.
Defeat for the second seed spells the end of his bid to overtake Rafael Nadal and finish as year-end number one.
Roared on by a raucous packed house at London's O2 Arena, six-time champion Federer looked in the groove from the start, cranking up the pressure on Djokovic's serve and dropping just three points on his own serve in the first set.
The Serbian upped his game at the start of the second set but Federer, 38, saved the one break point he faced and broke twice to canter to victory.
The third seed, making his 17th appearance at the ATP Finals, is into his 16th semi-final at the year-end event.
Djokovic needed to win the title to have a chance at knocking Nadal off the top spot, but now the Spaniard is guaranteed to finish the year as the top-ranked player for the fifth time, tying him with Federer, Djokovic and American Jimmy Connors.
"Great atmosphere, great opponent," said Federer, who hit 23 winners and made just five unforced errors. "It was definitely incredibly special. I enjoyed it from the beginning. I played incredible and I knew I had to because that's what Novak does. It was definitely magical."
Speaking about what was different from the Wimbledon final, where he squandered two championship points on his own serve, he said: "I won match point I guess.
"It was so close at Wimbledon. It was a privilege to play that match, so many ups and downs. I couldn't be more happy right now."
Federer finishes second in Group Bjorn Borg, behind Thiem, who also beat Djokovic earlier this week. The Swiss will face the Group Andre Agassi winner on Saturday.
Djokovic looked nervy at the start of the winner-takes-all contest, double-faulting twice in the third game, in which he was broken to love.
As cries of "Let's go Roger, let's go" rang around the cavernous stadium, Federer was dead-eyed on his serve, hitting eight aces, including a second-serve ace, in the first set.
Federer's service level dipped in the second set and 32-year-old Djokovic earned his first break point of the match in the fourth game, which the Swiss saved.
In the next game Djokovic slipped to 15-40 and sailed a forehand long to give Federer his second break of the match. The Swiss broke once more to close out victory.
COMMENTS
Comments are moderated and generally will be posted if they are on-topic and not abusive.
For more information, please see our Comments FAQ