World number one Nadal lost the opening set 6-0 after being outpowered by the Austrian ninth seed in New York, BBC Sport reported.
However, the 32-year-old Spanish top seed recovered to lead two sets to one before Thiem leveled in a tiebreak.
Nadal edged a tense fifth-set tiebreak to win 0-6, 6-4, 7-5, 6-7 (4-7), 7-6 (7-5).
The 17-time Grand Slam champion clinched victory when Thiem hit an overhead smash long on the first match point, the drama continuing until the last shot in an epic encounter lasting four hours and 49 minutes.
Nadal jumped over the net to console his Austrian opponent at the end, the pair embracing as those left inside Arthur Ashe Stadium rose to their feet to give them a thunderous ovation.
"I said to Dominic, 'I'm very sorry and keep going.' He has plenty of time to win. He will have his chances in the future without a doubt," Nadal said.
Asked about how he got through the tense moments, Nadal added, "Suffering is the right word. It was a great battle."
He will play Argentine third seed Juan Martin del Potro, the 2009 champion, in Friday's semifinals.
"It is good to have two days that probably give me the chance to be 100 percent in the semifinals," Nadal added.
Despite the drama, the 24,000-capacity Arthur Ashe Stadium was only about a third full when the match concluded under the lights, with many fans needing to leave early to get home.
Those who were left were treated to a tense final-set tie-break, which proved to be a fitting end to a great match.
"This match is going to be stuck in my mind forever – tennis is cruel sometimes," Thiem said.
"This match didn't deserve a loser, but there has to be one."
Thiem won 171 points in the match, five more than Nadal, and hit 74 winners compared to 55 by the Spaniard.
"If we skip the first set it was an open match from beginning to the end," Thiem added.
"Then it ends up in the fifth set tiebreak and he made one more point than me."