LONDON (AP) -- Dominic Thiem became the first player to advance from the group stage at the ATP Finals after outlasting five-time champion Novak Djokovic 6-7 (5), 6-3, 7-6 (5) in a seesaw crowd pleaser on Tuesday.
That leaves Djokovic facing a winner-takes-all match against Roger Federer -- in a highly anticipated rematch of this year's epic Wimbledon final -- to decide who will join Thiem in the semifinals.
Federer beat Matteo Berrettini 7-6 (2), 6-3 earlier, which means he and Djokovic both have a 1-1 record before playing each other in their last round-robin match on Thursday.
Thiem improved to 2-0 after beating Federer on Sunday, while Berrettini was eliminated after a second straight loss.
The Djokovic-Federer rematch was always going to be the highlight of the group stage at the season-ending tournament -- where they have 11 titles between them -- but now becomes even more of a blockbuster with a semifinal spot directly at stake.
Federer also has the added incentive of avenging that Wimbledon defeat, when the Swiss star missed two match points before losing 13-12 (3) in the deciding set.
"Actually, it's good for me to play him again, and maybe that all helps to get a chance to get him back," Federer said. "Maybe it took me a few days, couple weeks at most, to get over the Wimbledon loss. . We'll find out, but I think it's all flushed away from my side. A lot of water has gone under the bridge since then."
Federer has failed to reach the semifinals only once in his previous 16 appearances at the ATP Finals, in 2008, while Djokovic is trying to equal the Swiss star's record of six titles.
Thiem, for his part, has now beaten Djokovic in four of their last five meetings -- although the previous three wins came on clay, his favorite surface.
In the best match of the tournament so far, Djokovic needed to play near flawless tennis in the first set -- making just two unforced errors -- to hold off the Austrian.
At 65 minutes, the first set alone was longer than Djokovic's entire straight-sets win over Berrettini on Sunday.
But Thiem's aggressive shot-making started paying dividends after that, as he broke Djokovic to take a 2-0 lead in the second set and then again to start the third.
However, Djokovic fought back to level at 3-3 and then thought he had earned a match point when Thiem served at 5-4. With the score at 30-30, Thiem's forehand was initially called wide -- before a Hawk-Eye review showed that it had clipped the line.
Thiem held and then broke Djokovic at love -- only for the Serb to break right back when the Austrian served for the match.
Djokovic led 3-0 and 4-1 in the tiebreaker before Thiem won five straight points and then converted his second match point when his opponent hit a forehand into the net.
The two-time French Open runner-up, who finished with 50 winners and 44 unforced errors in a match that lasted 2 hours, 47 minutes, fell onto his back on the court before Djokovic gave him a thumbs-up as they shook hands at the net.
The early match wasn't nearly as dramatic.
Federer earned the only break point of the first set at 6-5, but Berrettini saved it with a forehand volley. In the tiebreaker, the Italian double-faulted to hand Federer a 5-2 lead and netted a forehand return on set point.
Federer broke Berrettini to open the second set, but had to overcome a slight wobble at 4-3. Federer trailed 15-40 in that game and had to save three break points in total before holding with an ace.
He broke again to seal the win when Berrettini netted a forehand.
On Wednesday, Rafael Nadal faces Daniil Medvedev in a rematch of this year's U.S. Open final, before defending champion Alexander Zverev plays Stefanos Tsitsipas in the late match.