Federer, aiming to add to his grand slam men's record total of 17 singles crowns, survived a pair of match points when down 15-40 on serve in the 10th game of the fourth set.
Monfils, the 20th seed, struck a backhand long to squander his first chance to claim victory and then Federer denied the Frenchman with a sizzling forehand winner to stay in the match.
From that point on, Federer took charge by closing out the fourth set and breaking Monfils in the first game of the fifth.
He took nine of the last 11 games in the 3-hour 20-minute quarterfinal at Arthur Ashe Stadium.
It marked the ninth time in his career that Federer escaped from a two-set deficit to win, previously accomplishing the feat in the third round of Wimbledon in 2012 against Frenchman Julien Benneteau.
Federer will play 14th seed Marin Cilic, who blasted his way past sixth seed Tomas Berdych 6-2 6-4 7-6(4).