London - Roger Federer produced a near-flawless performance as he avenged his Wimbledon defeat by Novak Djokovic and qualified for the last four of the ATP Finals with a 6-4, 6-3 victory on Thursday.
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 Djokovic's bid to overtake Rafael Nadal and finish as year-end No 1.
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.
Djokovic had won his past five meetings with Federer, including their epic five-set battle in the final at Wimbledon in July.
"He was the better player in all aspects and absolutely deserved to win," said Djokovic. "He served great, moved well, returned my serve very well.... He did everything right."
In Thursday's early match in Group Bjorn Borg, which was a dead rubber, eighth seed Matteo Berrettini beat Thiem 7-6 (7/3), 6-3.
Fifth seed Thiem did not hit the heights he reached during his three-set win against Djokovic, notching just 12 winners compared with 50 against the Serbian.
Stefanos Tsitsipas has already qualified for the semi-finals from Group Andre Agassi, leaving Nadal, defending champion Alexander Zverev and Daniil Medvedev to scrap it out for the other spot on Friday.
Results on the fifth day of the ATP Finals at London's O2 Arena on Thursday (x denotes seeding):
Group Bjorn Borg
Matteo Berrettini (ITA x8) bt Dominic Thiem (AUT x5) 7-6 (7/3), 6-3
Roger Federer (SUI x3) bt Novak Djokovic (SRB x2) 6-4, 6-3
Group Jonas Bjorkman
Lukasz Kubot/Marcelo Melo (POL/BRA x2) bt Rajeev Ram/Joe Salisbury (USA/GBR x4) 6-7 (5/7) 6-4, 10-7
Ivan Dodig/Filip Polasek (CRO/SVK x8) bt Raven Klaasen/Michael Venus (RSA/NZL x5) 7-6 (7/4), 6-4