In the standout match so far at London's O2 Arena, the Austrian fifth seed took the fight to the world number two, recovering from losing the first set to triumph 6-7 (5/7), 6-3, 7-6 (7/5)
Earlier, Federer put himself back in the mix at the end-of-season event with a 7-6 (7/2), 6-3 win against Italian debutant Matteo Berrettini in their round-robin clash.
Federer and Djokovic will face off on Thursday in a repeat of this year's Wimbledon final to determine who else will progress from Group Bjorn Borg.
Thiem was forced to play high-stakes tennis against the 16-time Grand Slam winner, taking the breath away with some of his inside-out forehands and single-handed backhands
Forced to play at his limit, he hit 50 winners compared with Djokovic's tally of 27 but also racked up 44 unforced errors.
ATP Finals: Djokovic has world no 1 Nadal in his sights
"This was really one of these special matches, what I've practised all my life for, all my childhood for," Thiem said.
"Really epic one in an amazing atmosphere, beating a legend of our game. And also I've qualified for the semi-finals, which is the best.
"Coming back from 1-4 (down in the deciding tie-break) was a little bit of luck, but it was an unbelievable match and one I'll never forget. Novak is the best player in the world and I had to do something special."
In a captivating first set the players swapped a break apiece but Djokovic, a five-time ATP Finals champion, edged the tie-break.
Undaunted, Thiem broke his opponent at the first opportunity in the second set and, with Djokovic's error count climbing, went on to level the match.
Thiem also drew first blood in the decider but cracked in the sixth game as Djokovic levelled the match and appeared to have engineered a switch in momentum.
The Austrian successfully challenged at 30-30 in the 10th game after his forehand was ruled out, preventing a match point for Djokovic and he toughed it out to level at 5-5.
He then broke Djokovic to love to earn a chance to serve for the match but stumbled and the decider went to a tie-break.
Nadal loses ATP Finals opener to Zverev as Tsitsipas triumphs
Still the drama was not finished. Thiem slipped to 4-1 down but battled back to win it on his second match point when Djokovic dumped a forehand into the net.
Third seed Federer had put himself under the cosh by losing his opening round-robin match to Thiem.
The six-time champion was not at his fluent best on Tuesday but ultimately had too much for his Italian opponent.
The Swiss upped his game to take the first set tie-break comfortably and broke immediately at the start of the second set to leave the big-serving Berrettini with too much to do.
Federer was asked after his win against Berrettini whether his defeat to Djokovic at Wimbledon had left emotional or mental scars.
"We'll find out, but I think it's all flushed away from my side," said the Swiss.
"A lot of water has gone under the bridge since then."
Djokovic is hunting a sixth ATP Finals title to pull level with Federer's record and is also seeking to pip Rafael Nadal to the year-end number one ranking.
On Monday, top seed Nadal lost his opener in Group Andre Agassi to defending champion Alexander Zverev while Stefanos Tsitsipas beat Daniil Medvedev.
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