NEW YORK – Clearly frustrated by his play and opponent, Roger Federer of Switzerland whacked his racket on the top of the net after a missed volley. Moments later, he barked at the chair umpire: “What’s wrong with you, man?”

Not long after that, Federer found himself in the precarious position of twice being one point from defeat.

Steady as ever, even at 33, Federer held on. Coming back from a two-set deficit, and saving two match points along the way, Federer edged 20th-seeded Gael Monfils of France 4-6, 3-6, 6-4, 7-5, 6-2 on Thursday night to reach the U.S. Open semifinals for the first time since 2011.

Frustrated by Monfils’ unpredictable style, flummoxed by the swirling wind and missing shots he normally makes, the second-seeded Federer faced the two match points while trailing 5-4 in the fourth set.

“When I was down two match points, that’s when I wasn’t feeling so great anymore,” Federer said with a chuckle. “I thought, ‘This is it. This is the last point, man. Go down fighting. Don’t miss an easy shot and let him have it.’ ”

He got out of that hole, starting a five-game run that put the match in his control for the first time. It helped that Monfils’ quality of play dipped, including what wound up being a total of 10 double-faults.

This was the ninth time Federer has won a match after dropping the opening two sets.

“I served well and stayed in the match and somehow turned it around,” Federer said. “I was really starting to play better and better as the match went on.”

Monfils was trying to reach his second career semifinal in a Grand Slam event. Instead, Federer advanced to his 36th major semifinal, ninth at Flushing Meadows. Five of Federer’s record 17 major singles titles have come at the U.S. Open, but he exited in the quarterfinals in 2012 and the fourth round in 2013.

On Saturday, Federer will play 14th-seeded Marin Cilic of Croatia.

The other semifinal will be No. 1 Novak Djokovic of Serbia against No. 10 Kei Nishikori of Japan; their quarterfinal victories came Wednesday.

Cilic wasn’t allowed to play in last year’s U.S. Open, forced to the sideline by a four-month doping suspension he says he didn’t deserve. But Cilic reached the second major semifinal of his career, and first since 2010, by beating No. 6 Tomas Berdych of the Czech Republic 6-2, 6-4, 7-6 (7-4).

“I mean, it was a difficult period. I didn’t know when I’m going to start back. But (it) was also (a) good period for me,” Cilic said of the suspension. “I matured a bit more and I was working, day after day.”