Thiem defeated No. 5 Kevin Anderson, an Open finalist last year and a Wimbledon finalist this year, 7-5, 6-2, 7-6 (2), to set up a meeting with Nadal, who had more to deal with than he might have thought in Basilashvili.
Nadal edged a tense fifth-set tie-break to win 0-6 6-4 7-5 6-7 (4-7) 7-6 (7-5).
This one was never easy: Nadal trailed by a break in the third set before taking it.
Thiem, who had also tasted defeat against Nadal in this year's French Open, is a rising star of the game who has been on the wrong side of the Spaniard's warrior-like tenacity.
Meanwhile, Serena Williams survived her first test of the tournament to reach the quarter-finals for the 15th time.
He'll face 2009 champion Juan Martin del Potro next. Thiem then grabbed a 4-3 lead in the third which he stretched to 5-3 but then it was his turn to crack as Nadal raced away with three games to claim a two sets to one lead.
But Basilashvili stunned Nadal in the third set tie-break and even retrieved a break for 3-3 in the fourth set before Nadal's greater composure paid off.
Eventually, the world No 1 persevered to keep his challenge for an 18th Grand Slam alive.
Thiem made him work for this win.
Six-time women's victor Serena Williams booked her place in the last-eight with a 6-love, 4-6, 6-3 victory against Kaia Kanepi.
Williams delivered 13 aces, part of a 35-12 edge in winners.
When it ended, on an overhead by Thiem that sailed long, everyone in Nadal's guest box - a group that included actor Ben Stiller - leaped to their feet to celebrate. The 32-year-old Spaniard, a 17-time Grand Slam champion, knows better than anyone how to will a way out.
But the 25-year-old Austrian was ultimately the one bowing out of the US Open; the scoreline reading 0-6, 6-4, 7-5, 6-7, 7-6. Law and Whitaker say it feels like there's an irresistible force behind del Potro that's pushing him to the title.
Defending men's champion Nadal is up against Georgia's Nikoloz Basilashvili. That put her into the match against Kanepi, the 44th-ranked Estonian who upset top-ranked Simona Halep in the first round and is seeking her second consecutive quarterfinal in Flushing Meadows.
"He's young, he has plenty of time to win big tournaments", he said on court.
"To win in straight sets in every round is good for the body and physical condition", said del Potro.
When they came back for the final set, both players were still in top form.
But Sevastova broke again to go up 3-1. But once again Nadal stepped up the level, saved two break points in the game and then went on to claw back to 4-4.