Nadal beat Anderson a year ago for his third US Open title.
The world number one looked like he would cruise to an easy win after pocketing the first two sets but the Georgian stepped up his game to take the third.
"It s a big victory for me", said the 32-year-old Nadal, the champion in 2010, 2013 and 2017.
I could go very far back like I do on clay usually. "He's a great guy, a close friend who will have many more opportunities to win the big titles".
"He has a great attitude and is a great fighter".
Austria's Thiem knocked out South African fifth seed Kevin Anderson - the man who lost in the final to Nadal at Flushing Meadows past year - in three sets earlier on Sunday.
Although that gap swiftly vanished, the Spaniard never quite got to grips with the third and stumbled in the tiebreak, pegged back when Basilashvili came forward following a big serve to press home his advantage.
Anderson, who has reached the final at two of the last four Grand Slams, leads his fourth-round opponent Thiem 6-1 in their head-to-head but fell to the 24-year-old in May in the Madrid Masters semi-finals. He is also the top seed at the US Open.
Defending champion Nadal suffered a "bagel" in the first set but still won 0-6 6-4 7-5 5-7 7-6 to avoid the same fate as Roger Federer.
The Spaniard saved a break point in games nine and 11 but he stood no chance in the tie break, losing it 7-4 following a routine forehand that he sent into the net, handing the set to his rival and setting up a decider after more than three and a half hours of unbelievable battle!
Juventus maintain 100% Serie A start but concerns remain about misfiring Ronaldo
He has had 23 shots without scoring, eight more than any other player who has yet to score in one of Europe's top five leagues. First, he was edged out by former Real Madrid teammate Luka Modric for UEFA's player of the year award.
US Open: Roger Federer gives rebel Nick Kyrgios a harsh lesson
Just the way he goes about things, I could take a leaf out of his book. "Things worked well for me today". The winner-around-the-net-post has been done before, but Federer makes it even better.
Woodward: White House officials hid papers from 'unhinged' Trump
He said he never said about the president the things the book claims he said, nor did anyone in his presence. Woodward did not interview Trump for the book, but Trump did reach out to Woodward in August.
But he took the tiebreaker before Nadal just proved the steadier of the two in the final set decider. The day's other last-16 duel sees United States 11th seed John Isner tackle fellow big-server Milos Raonic, the 25th seeded Canadian.
Anderson swept the match's final game by getting a service victor, forced forehand error, ace and forced backhand error off Shapovalov in that order.
"John is a friend of mine and he deserves to be in the quarters as well", said Del Potro, who has not dropped a set so far in NY.
Wawrinka had 29 winners, 28 unforced errors and was unable to break the hard-serving Raonic for the duration of the match.
'I had a tough start and then I stayed in the match in some way.
"I had a shower, lay on the table and I didn't want to come back again".
He is in a relationship with French tennis player Kristina Mladenovic, also 25.
He'll take on No. 11 seed John Isner of the U.S.
Isner paid tribute to Del Potro. "It was very painful‚" Thiem said.
Wednesday's quarter-finals will see two-time champion Novak Djokovic face Millman, the world number 55.