The Spaniard looked on course to breeze into the fourth round and continue silencing his critics when he cruised into a 6-3 6-4 lead.
However, the Italian refused to leave without a fight as he won the next two sets 6-4 6-3, before edging the decider 6-4 to settle a gruelling four-hour war of attrition in New York.
Nadal, who had only dropped one set in his first two matches, started well this morning and inflicted two breaks of serve, either side of one from Fognini, to lead 3-2.
Those broken service games proved key in deciding the opener as the duo held their respective serve for the remainder of the set.
With Nadal vying for an eighth successive fourth-round berth, he applied the pressure against his serve, while winning his own service, and it eventually paid off when he broke to move 5-4 ahead.
Serving for a 2-0 lead, Nadal, who had not progressed past a Grand Slam quarter-final this year, then had three set points but Fognini pegged him back at deuce, but he won the next two to take a big step into the next phase.
He broke his Italian counterpart in the third game en route to a 3-1 lead as he moved halfway toward victory, but Fognini - who had never progressed past the third round - battled back gamely.
The world number 32 hit back with two breaks of his own in the sixth game and, crucially, the 10th as he reduced the arrears.
Another break in the opening game of the fourth set saw Nadal enjoy a perfect start, but his resistance began to wane as Fognini refused to go quietly, pulling out breaks of serve in the fourth and eighth games on his way to levelling up the match at 2-2.
Seven of the first nine games in the decider went against the serve, but Fognini, who broke straight back to lead 5-4 following a lengthy eighth game, held serve in timely fashion to close out the win and pile more misery on Nadal.
The 28-year-old will face Feliciano Lopez in the next round.