Nadal has never been beyond the last eight of the US Open
World number one Rafael Nadal was given an unexpected test by Sam Querrey of the United States before booking his place in the US Open quarter-finals.
The Spaniard looked in control when he led by a set and 5-3 but Querrey took the next four games for the second set.
Querrey, ranked 55th, was only edged out of the third set on a tie-break.
But Nadal came through a tense fourth for a 6-2 5-7 7-6 (7-2) 6-3 victory and he will meet Querrey's compatriot Mardy Fish in the last eight.
"Very tough," said Nadal, who is yet to make it past the last eight at Flushing Meadows, after his fourth-round win.
"I'm very happy for the victory. Now I'm in my best round at the US Open and I hope to play better in the next round."
I was just taking my forehand and trying to rip it as hard as I could. He's just too good
It was a strangely subdued performance by Nadal, who lost his way completely in the second set, especially with his serve.
Nadal was broken three times in the second set alone and, even when he took a 4-2 lead in the third, he could not shake off a determined Querrey, who was inspired by a passionate home crowd.
A double-fault saw Querrey level at 4-4 but just as worrying for the Wimbledon champion were some wayward forehands which were undermining his attacks.
Only in the tie-break did he look like his old self but, despite taking that easily, he did not have things all his own way in the fourth set either.
A long forehand by Querrey saw Nadal break to go 3-2 up but Nadal had to save seven break points in the next game before eventually holding and serving out for victory.
"At the start I was a little nervous but after an hour I was hitting my shots pretty good," said Querrey.
"I was just taking my forehand and trying to rip it as hard as I could. He's just too good."
Fish was in fine form as he claimed a one-sided 7-5 6-2 6-2 victory over 32nd seed Gael Monfils of France.
The world number 35, who knocked out ninth seed James Blake in the third round, pressured Monfils from the start by attacking whenever possible.
Monfils fought hard in the first set but ended up well beaten.
Fish, who had never gone beyond the second round at Flushing Meadows before this year, struggled with his serve against Monfils but volleyed superbly throughout.
The Frenchman, who was playing on his 22nd birthday, also struggled with a knee injury that he sustained midway through the second set but by then his resistance was already fading.
Monfils struggled to deal with Fish's tactics, which involved him getting to the net at every opportunity, and many of the American's 49 winners were smashes.
"I knew I had to keep the points short by coming forward," Fish said. "I am never, ever going to beat someone like that from the baseline.
"My volleys are some of the best parts of my game. I volleyed better than I hit my forehand so I might as well try to do that.
"I think confidence is a big thing. It comes back to wanting to do well here and just having that extra amount of energy in the matches.
"I am desperate to do well and I am doing everything in my power to do well. It's not every tournament that I make the quarters of a Grand Slam - it has only happened twice now."
Britain's Andy Murray, the sixth seed, beat Switzerland's Stanislas Wawrinka 6-1 6-3 6-3, and will next play Argentina's Juan Martin del Potro, who defeated Kei Nishikori of Japan 6-3 6-4 6-3.