The 38-year-old avenged his agonising Wimbledon final defeat by Djokovic in July, winning 6-4 6-3 to deny the Serbian the world number one spot in the process.
The illustrious pair, with 11 titles between them, were both expected to progress from the group stage but Dominic Thiem’s impressive form meant only one of them could join him.
It was Federer who maintained his proud record of having never failed to reach the semi-finals here at London’s 02, and he can now bid for a record seventh title over the weekend.
Four years since his last win over Djokovic, and four months since he blew those two championship points at Wimbledon, an elated Federer said: “It was a great atmosphere, a great opponent, here at the 02, incredibly special, I enjoyed it from the beginning.
“I played incredibly well and I knew I had to because that’s what Novak can do.
“What did I do differently from Wimbledon? I won the match point I guess.
“You move on, try harder next time round and hope the luck goes for you. I couldn’t be happier right now.”
It was a strange performance from Djokovic, who made three double-faults in his first two service matches, dropping the second to love.
By contrast it was a stunning first set from Federer, even by his own impeccable standards, as he fired down eight aces, hit 12 winners and made just one unforced error.
The Swiss master, a favourite with the crowd if not the bookmakers, broke again at the start and the end of the second set to wrap up a memorable win.
He can now put his feet up on Friday ahead of a semi-final showdown with Stefanos Tsitsipas, Alexander Zverev, Daniil Medvedev or Rafael Nadal, who is now guaranteed to end the year at the top of the rankings.
“You always play better as a tournament goes along,” added Federer.
“Dominic has been supreme in our group and put us in this situation, there was a lot riding on the match. I had a clear game plan and it worked to perfection. It was a great performance from me tonight.
“Am I looking forward to the weekend? A lot. I’m happy to stick around. I didn’t make any plans yet!”
Djokovic, who failed to reach the semi-finals for the first time since 2011, said: “There was not much that I did right this match, to be honest.
“I mean, realistically he was better player in all aspects and absolutely deserved to win.
“He served great, moved well, returned my serve very well. From his end, I think he did everything right.
“From my end, I was just playing too neutral. I couldn’t read his serve well. Just a pretty bad match from my side.”
In the afternoon’s dead rubber, Thiem was beaten in straight sets by Matteo Berrettini, who ended his stay in the capital on a high by becoming the first Italian to win a match at the Finals.
Earlier, Joe Salisbury’s bid to reach the semi-finals in the doubles came to an end.
The 27-year-old, Britain’s sole representative at the Finals, and his American partner Rajeev Ram lost a match tie-breaker to Lukasz Kubot and Marcelo Melo.