Vincent Trocheck of the New York Rangers celebrates his first-period...

Vincent Trocheck of the New York Rangers celebrates his first-period goal against the Washington Capitals in Game Two of the First Round of the Stanley Cup Playoffs with teammates Erik Gustafsson and Alexis Lafreniere at Madison Square Garden on Tuesday. Credit: Jim McIsaac

All along, the Rangers knew the Washington Capitals would give them a tougher fight in Game 2 of their first-round playoff series than they did in Game 1 on Sunday. And they were right. The underdog Capitals did push the Rangers harder on Tuesday night at Madison Square Garden.

In the end, though, despite falling behind early in the first period, and despite having to withstand a massive push from the visitors at the end, the Rangers hung on against a desperate Washington team, surviving a hairy final two-plus minutes after the Caps pulled their goalie to emerge with a 4-3 victory that gave them a 2-0 series lead.

The series shifts to Washington for the next two games, with Game 3 upcoming on Friday at Capital One Arena.

“Right now, it doesn’t matter what the series is — 2-0, 1-0, we just need to play the next game the right way,’’ said Rangers goaltender Igor Shesterkin, who made 22 saves.

The game was a choppy affair, with the teams combining for 11 minor penalties, which turned it into a battle of special teams. The Rangers won the battle, going 2-for-6 on the power play, while also scoring a shorthanded goal. Washington was 2-for-5 with the man advantage.

K’Andre Miller’s shorthanded goal at 16:52 of the second period ended up being the game-winner. Miller scored when he took a back pass from Mika Zibanejad after a pretty tic-tac-toe sequence with Chris Kreider, and lifted a shot over the blocker pad of Washington goalie Charlie Lindgren to give the Rangers a 4-2 lead.

“I don’t get how Mika sees me there,’’ Miller said. “It’s an unreal play by him. Kreids taking out three of their guys bringing all the attention to him, and I was just sneaking in down the pipe, and just trying to get something on net.’’

The goal was one of few pretty plays in what was a pretty ugly-looking game. Washington took the early lead on a goal by Connor McMichael at 5:09 of the first period, but Vincent Trocheck redirected a pass from Erik Gustafsson (two assists) to tie it at 7:56. Then, Zibanejad gave the Rangers their first lead with a power-play goal, taking a pass from Trocheck and lifting a shot over Lindgren at 14:28.

Dylan Strome tied it for Washington with a power-play goal at 4:14 of the second period, but Jack Roslovic scored the Rangers’ second power-play goal at 12:26. After Miller’s goal put the Blueshirts ahead 4-2 entering the third period, Tom Wilson scored a power-play goal at 11:45 of the third period to pull Washington within 4-3, but the Rangers managed to hang on from there.

“It was ugly a lot of the time, I think,’’ Jacob Trouba said. “There was obviously some good plays that were made. ‘Gus’ Gustafsson] with a couple of great passes, obviously Key’s goal was impressive. But for most of the time, it was kind of a mucky, chip it out, chip it in, they chip it in, break it out . . . definitely more of a grinding game. More of the playoff feel to it.’’

Zibanejad had admitted at the Rangers’ morning skate that he had not had his best season, statistically (26 goals, 72 points), but he was a force on the ice all game.

“Mika’s been awesome for us, especially these last two games,’’ Miller said. “He’s doing a lot of different things for us on the power play, PK, 5 on 5. At the end of the game, beginning of the game, whatever you want to say. He’s been doing it all.’’

Trocheck, too, was huge, scoring a goal and having an assist and winning 17 of 25 faceoffs.

“I think they’ve been there all year,’’ Rangers coach Peter Laviolette said of Zibanejad and Trocheck, his top two centers. “We talked about Troch, and Mika had a heckuva game tonight. He was noticeable a lot — specialty teams, 5-on-5, I thought he did a terrific job.’’

The Rangers outshot Washington 27-25, and outhit them 35-26. And they did another masterful job on Washington star Alexander Ovechkin, holding him to one shot on goal, after he had none in Game 1.

“He’s a player that can make a difference in a game,’’ Laviolette said. “We’re, I guess, mindful of that, and do our best to check him.’’

Notes & quotes: Rangers rookie Matt Rempe had only 7:34 of ice time but led the team with seven hits . . . Adam Fox had team-highs with five blocks and 23:22 of ice time. Defenseman John Carlson led the Capitals with 30:49 of ice time.