Rafael Nadal recovered from a first-set bagel to defeat Dominic Thiem and reach the US Open semi-finals following another late-night classic in New York.

Twenty-four hours after Roger Federer fell to John Millman, his old rival avoided following him out of the tournament, but only just, completing a 0-6, 6-4, 7-5, 6-7 (4-7), 7-6 (7-5) victory at 2.03am.

Ninth seed Thiem became the first player since Andy Roddick in 2004 to win a love set against Nadal in New York but the defending champion once again dug deep to come out on top of a gruelling battle played in more punishing humidity.

Nadal will now face third seed Juan Martín del Potro, who defeated John Isner, in a repeat of last year’s semi-final.

Remarkably, Thiem was the first top-20 player Nadal has faced at Flushing Meadows since his final win over Novak Djokovic in 2013, with last year’s title seeing him take on a succession of unexpected opponents.

And Thiem, the only man to beat Nadal on clay for the last two seasons, set about showing his opponent he meant serious business in his first grand slam quarter-final outside of the French Open.

The Austrian blasted 13 winners, made only two unforced errors and allowed Nadal just seven points in winning an extraordinary opening set.

It was only the fourth time in his long grand slam history that Nadal had lost a set 6-0 and just the third time at any level in nearly seven years. But the last time, against Philipp Kohlschreiber in Miami last spring, he fought back to win the match.

Nadal’s ability to look only forward and forget what went before is one of his most important strengths and he set about turning around the match, closing in on the baseline, forcing Thiem to play one more ball and, eventually, to go for too much.

The Spaniard secured the break he wanted for 5-3 only to give it back but a sloppy game from Thiem, who turned 25 on Monday, handed him the set anyway.

The momentum was with Nadal but Thiem regrouped in the third set and began to again blast winners into the corners. But, as in the second set, when the time came to keep his foot on Nadal’s throat, he instead loosened the pressure and lived to regret it.

Thiem was broken serving for the set and then could not hold on for the tie-break, saving two set points but not a third after planting a volley wide with the whole of the court available.

The fourth set was a wild 81-minute ride that began with Thiem facing break points, saw the Austrian threaten a double break before being pegged back and then a weary Nadal miss a chance to win the match.

With Thiem serving at 5-6 and 30-30, a desperate lunging forehand looked to be easy pickings for Nadal at the net only for the 32-year-old to net it.

Thiem held on for the tie-break, where another unexpected Nadal error, this time a short forehand into the net, sent the match into a deciding set.

With the clock ticking towards 1am and transport options dwindling, many fans headed for the exits while the two adversaries battled on.

Having looked the more weary of the two, it was Nadal who was applying the greater pressure and at 5-5, 0-40 it seemed this was his chance. But Thiem saved all three break points before denying Nadal a fourth opportunity with a stunning volley at the end of a remarkable point.

That they were still able to produce tennis of such quality was astonishing. There was no let-up in the tie-break and, after four hours and 49 minutes, it was Nadal who claimed victory when Thiem sent a smash long.

The Austrian hung his head before being consoled by Nadal who then held his arms aloft in celebration and relief.