The second seed, who has not lost before the last 32 in New York since 2004, trailed by a set and 4-2 and was struggling to put the ball in the court.
But, with some help from a similarly wayward opponent, Nadal turned things around and finished strongly in a 2-6 6-4 6-2 6-1 victory to set up a clash with fellow veteran Richard Gasquet.
Having sought treatment for blisters in the second set, there was a bizarre moment in the fourth when Nadal's racket bounced off the court and into his nose, drawing blood and prompting the 36-year-old to lie down on the court and seek medical attention.
He said afterwards: "At the beginning I thought I broke the nose because it was a shock. It was very painful.
"(There's a) little bit of pain but (I'm feeling) good. Happy after a terrible start. I don't understand yet how I started that bad because the feeling before the match was good.
"But these kind of things sometimes happen so you need to accept and keep going. That's what I did. I was lucky that Fabio made some mistakes and I was able to start putting some balls in and finished the match playing obviously better, much better.
"I am practising much, much better than what I am playing. That"s a positive thing. Then I need to make that happen in the matches."
The Spaniard had played only one match since sustaining an abdominal tear at Wimbledon prior to arriving at Flushing Meadows and was wary of fully committing to his serve.
It was not just the serve that was having an off day initially on Arthur Ashe Stadium, with Nadal spraying groundstrokes and missing routine balls.
Across the first two sets he made 27 unforced errors and dropped serve five times, including four in a row.
Fognini had not had to do anything special to put himself in a position to repeat his 2015 triumph here over Nadal but, when the Spaniard began to at last find his range, his opponent could not respond.
He was fully in control by the time the nose incident occurred and it did not derail his momentum, while he can take confidence from the fact he has beaten Gasquet in all 17 of their professional meetings.
Nadal's countryman Carlos Alcaraz had a more comfortable time of it earlier in the day, defeating Federico Coria 6-2 6-1 7-5.
The third seed was delighted with his level and concentration, saying: "I'm really happy with my performance today. I think I played really, really well. I had to be really, really focused. Grand slam, every minute on courts counts. You have to be really focused and show your best level. I think I did it today."
Andrey Rublev and Jannik Sinner, who both had five-set battles in the first round, won comfortably this time but eighth seed Hubert Hurkacz is out after a shock 6-4 4-6 7-6 (5) 6-3 loss to Ilya Ivashka and Grigor Dimitrov also fell.