Revenge was sweet for Roger Federer as he defeated Novak Djokovic 6-4 6-3 in a showdown to reach the last four at the ATP Finals.

The 38-year-old avenged his agonising Wimbledon final defeat by Djokovic in July, denying 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 at London's O2, 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 O2, 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 the 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."

Matteo Berrettini signed off his tournament by becoming the first Italian to win a match at the ATP Finals with a surprise 7-6 (7-3) 6-3 victory over Thiem.

The big-serving 23-year-old, beaten in his first two matches by Djokovic and Federer, knew he could not qualify for the semi-finals, while Austrian Thiem was already through.

It was at least a winning end to a successful season for Berrettini, who began the year ranked 54.

The eighth seed and final qualifier for the season-ending tournament said: "I'm really proud of myself and for my team, my family and my friends.

"It's been an unbelievable season and I didn't expect at the beginning to be here. I hope to be back next year. I'm happy to finish with a win.

"I always have great fights with Thiem. I was able to stay mentally focused even when I lost my serve, and I played a great tie-break. I'm not feeling great physically so I'm happy with my performance."

Thiem's below-par display could be put down to the cold he has been carrying this week.

The 26-year-old fifth seed at least has an extra day to recover before the semi-finals.

He said: "I think I felt the two first matches a little bit, and then also it's a bit of a tricky situation to know that I'm already through. So all the attention, the adrenaline, is set down a little bit.

"Of course I was still trying to win that match, 100%. But at the same time, I knew I had to take care for Saturday, because obviously it's the way more important match there."