Ferrer's 6-7 (3/7), 6-4, 7-6 (7/4), 6-2 victory marked the first time in five meetings stretching over three years that he had managed to get the better of Nadal putting him into a quarter-final match against Juan Ignacio Chela.
"I am very tired. I had to run a lot," said the 25-year-old Ferrer.
"I am happy for myself - it is a very special night for me but I am sorry for my friend Rafa. In the tough moments he plays very well."
For Nadal, who has struggled with a knee injury from the start of the tournament, it was another US Open flop and he has failed to get past the last eight in five campaigns to date.
The match between two tried and trusted clay-courters started at about 10pm (local time) and any hopes of a quick conclusion were stymied as they shared the first two sets in just under two hours.
Ferrer was in command of most of the rallies against a curiously subdued-looking Nadal and it was no surprise when he took an all-important third set.
Sensing blood, Ferrer kept up the pressure as a struggling Nadal needed treatment on his knee tendons and for cramps in his left hitting hand.
The older of the two Spaniards broke early in the fourth set to lead 4-2 and then Nadal crumpled over in pain in a corner after a Ferrer smash made it 5-2.
The 20-year-old Mallorcan gamely came back out to serve, but it was soon all over, Nadal pushing a speculative lob long on match point. © 2007 Australian Broadcasting Corporation