The Spaniard lost the first set and was 4-2 down in the second before recovering to secure a 2-6 6-4 6-2 6-1 win over the Italian.
Nadal also drew blood after hitting himself in the nose with his racquet during the closing stages of the match.
"I was a little bit dizzy and it was a little bit painful," said Nadal.
He was hurt when his racquet bounced back off the court as he stretched for a ball and the 36-year-old needed a medical timeout after the incident.
"At the beginning I thought I broke the nose because it was a shock," added Nadal.
"[There's a] little bit of pain but [I'm feeling] good."
The 22-time Grand Slam winner did not let the issue impact him as he closed out the match comfortably - a contrast to the way he started against Fognini, who defeated Nadal from two sets down at the US Open in 2015.
Nadal made 27 unforced errors in the first two sets and dropped serve five times, including four in a row, before improving and setting up a third-round tie against 36-year-old Frenchman Richard Gasquet.
"Happy after a terrible start. I don't understand yet how I started that bad because the feeling before the match was good," said Nadal.
"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."
Gasquet, a 2013 semi-finalist in New York, knocked out Serb 32nd seed Miomir Kecmanovic, winning 6-2 6-4 4-6 6-4.
Spaniard Carlos Alcaraz also progressed into the US Open third round with an impressive straight-set win over Federico Coria.
The 19-year-old third seed continued his bid for a maiden Grand Slam title by beating Argentine Coria 6-2 6-1 7-5 on Arthur Ashe Stadium.
Alcaraz is one of four players who could end the New York tournament as the world's top-ranked men's player.
He will face Jenson Brooksby next after the American upset Croatia's Cincinnati winner Borna Coric 6-4 7-6 (12-10) 6-1.
Coric, who missed seven set points in the second set, complained to the umpire about Brooksby's celebrations during the match, with his frustration boiling over early in the third set when he smashed his racquet on the court.
There was a surprise loss for Polish eighth seed Hubert Hurkacz, who fell to a four-set defeat by Belarusian Ilya Ivashka.
The world number 73 prevailed 6-4 4-6 7-6 (7-5) 6-3 to set up a match against Italy's 26th seed Lorenzo Musetti.
Russian ninth seed Andrey Rublev and Italian 11th seed Jannik Sinner both progressed.
Rublev won 6-3 6-0 6-4 against South Korean Kwon Soon-woo and will meet Canadian 19th seed Denis Shapovalov, a 6-4 4-6 6-3 6-2 victor over Spain's Roberto Carballes Baena.
Sinner, a quarter-finalist at both the Australian Open and Wimbledon this year, defeated American Christopher Eubanks 6-4 7-6 (10-8) 6-2. The 21-year-old will meet Brandon Nakashima in the third round after the American, also 21, knocked out Grigor Dimitrov, the Bulgarian 17th seed, 7-6 (7-5) 7-5 6-3.
Meanwhile, Croat 15th seed Marin Cilic overcame Spaniard Albert Ramos-Vinolas 6-3 7-6 (7-4) 6-3 and will face Briton Dan Evans, who won in four sets against Australian James Duckworth.
Argentine Diego Schwartzman, seeded 14th, defeated Australian Alexei Popyrin 7-6 (7-3) 7-5 7-6 (8-6) and will play American 22nd seed Frances Tiafoe, who beat Australian Jason Kubler 7-6 (7-3) 7-5 7-6 (7-2).
Meanwhile, Wimbledon finalist Nick Kyrgios has been fined for spitting on court for the second consecutive Grand Slam.
The Australian, who faces JJ Wolf in the third round on Friday, has been fined $7,500 (£6,500) for spitting on the court during the third set of his second-round victory over Benjamin Bonzi. It is the biggest fine of the US Open so far.
Kyrgios was fined $10,000 for spitting towards the crowd during his first-round match against Britain's Paul Jubb at Wimbledon.
'I have to go for it' - Alcaraz
Alcaraz, whose first opponent Sebastian Baez retired with injury when trailing by two sets and a break, kickstarted a fine victory as he broke opponent Coria's serve twice to claim the opening set with five successive games.
His winning streak extended to nine games as he then closed in on victory with three breaks of serve in a commanding second set.
A double fault from Coria handed Alcaraz a 3-1 lead in the third set and the Argentine threw both arms in the air in celebration after finally managing to break his opponent's serve on his way to restoring parity at 4-4.
With nothing to lose, Coria began to play his best tennis and he maintained that momentum as he threatened to force Alcaraz to play a fourth set.
But the classy Spaniard withstood five break points to hold for a 5-4 lead, before clinching his first match point with a backhand winner on Coria's serve in the 12th game of the set.
Alcaraz hit a total of 46 winners in a devastating display, while he now has 46 victories this season - level with Stefanos Tsitsipas for the most on the men's ATP Tour in 2022.
"Federico started to play really well and I had to stay calm and stay focused in the tough moments," said Alcaraz.
"It has been a great year for me and it is not the end yet. I am playing really well and I have to go for it. I have to look forward and stay the same person, the same player, and go for it."