The 33-year-old second seed, bidding to become the oldest winner of a Grand Slam title in more than 40 years, was staring down the barrel of a demoralizing exit when French 20th seed Monfils had two match points in the 10th game of the fourth set.
But once they were saved, the lifeblood was suddenly sucked out of the flamboyant but unpredictable 28-year-old Frenchman whose notoriously fickle stamina failed him in a one-sided fifth set.
The victory was Federer's 26th in 27 night-time matches in New York and put him just one win away from a career 600 victories on hard courts, a landmark he can reach if he defeats Marin Cilic to make the final.
Croatian 14th seed Cilic toppled sixth-seeded Czech Tomas Berdych 6-2, 6-4, 7-6 (7/4) earlier Thursday to reach his first US Open semifinal.
Federer's win was his ninth from two sets to love down and first at a major since he had to engineer a similar Houdini act against another Frenchman, Julien Benneteau, at Wimbledon in 2012 on his way to his 17th and most recent major title.
"Gael played great tennis but even when I was two sets down I knew the finish line was still far away for him," said Federer after the three-hour 20-minute duel put him in his first semifinal since 2011.
"I knew I could play better tennis but on match point I wasn't feeling so great anymore.
"I just thought this could be the last point, don't give it away on an easy shot, make him work for it."
As Monfils opened-up a two-set lead, Federer was in danger of falling to pieces with two uncharacteristic losses of his famed composure when he berated umpire Carlos Ramos and smashed his racquet on the net.
But eventually it was Monfils, playing in his first US Open quarterfinal since 2010, who suffered the most serious power loss with his failure to convert his two match points in the 10th game of the fourth set leading to a brief final set which saw Federer sweep to victory.
Roger Federer now faces a stiff test on Saturday from Cilic, the Croat who sees a first Grand Slam title as a perfect way to repair his reputation.
Federer has a 5-0 career edge over Cilic including a four-set win in New York in 2011 and at Toronto in three tough sets last month.
Cilic, the 25-year-old 14th seed, missed last year's US Open sitting out a controversial doping ban handed out after he tested positive for a banned stimulant contained in a supplement bought over-the-counter by one of his staff.
A six-month ban was eventually reduced to four by the Court of Arbitration for Sport, but Cilic still believes the entire process was unjust.
"It angered me how all the process went because it was not fair to me. It wouldn't be fair to any tennis player," Cilic said.
Cilic was a semifinalist at Australia in 2010 and a two-time quarterfinalist in New York in 2009 and 2012.
But that final step has always proved impossible for Cilic, who now has 2001 Wimbledon champion and compatriot Goran Ivanisevic in his corner as coach.
"I'm looking forward to playing Marin," said Federer. "He's a great guy. We had a tough, tough match in Toronto. I think I needed nine match points to close him out and beat him at midnight, 6-4 in the third, so we know what to expect."
A win on Saturday would put him in a seventh final but his first since 2009 when he was deposed as champion by Juan Martin del Potro.
World number one Djokovic, a seven-time Grand Slam title winner, faces Japan's Kei Nishikori in Saturday's first semifinal.