Roger Federer perhaps thought he was playing Nadal — not Nagal — in the U.S. Open’s first round.

That’s how tight Federer looked as he faced the qualifier from India, 190th-ranked Summit Nagal, making his Grand Slam debut.

Somehow, the Swiss Maestro lost the first set 6-4. On set point, he knocked a forehand long for his 19th unforced error. So much for the mismatch.

But rather than losing in the biggest upset in U.S. Open history, the third-seeded Federer rallied with ease to post a 4-6, 6-1, 6-2, 6-4 victory at Arthur Ashe Stadium in Monday night’s second match. He needed 2 ¹/₂ hours to pull it off with the match ending just before midnight.

The unshaven Federer moved to 19-0 in first-round Open matches.

“I played like my beard today — rusty,’’ Federer said. “I’m going to shave it off for the next match.

“I just tried to forget it, stay tough. It was a tough first set for me. Credit to him to play a solid first, and [I] was missing a lot of balls and hopefully serve better. It came back just in time.”

Nagal, 22, had reached his first main draw of a Grand Slam after he won three qualifying matches, even coming from a set and a break down to win his finale. The scrappy baseliner was genuinely delighted when he was placed next to Federer’s line in the draw.

“I want to play him,’’ Nagal told the ATP website before the match. “It doesn’t matter. It’s not about winning or losing all the time. It’s just the experience. It’s playing someone who has 20 Grand Slams.”

Federer was indeed off-kilter after having a lack of match action since a classic loss in the Wimbledon final against Novak Djokovic. Federer didn’t play in Canada and lost in the first round in Cincinnati.

It got a little dicey in the fourth set when Federer served for the match at 5-4 and faced triple-break point before rallying to seal the match as he looks to break an 11-year Open-title schneid.