Rangers left wing Artemi Panarin celebrates with goaltender Jonathan Quick...

Rangers left wing Artemi Panarin celebrates with goaltender Jonathan Quick after defeating the Bruins in an NHL game Thursday in Boston. Credit: AP/Steven Senne

BOSTON — The gantlet of opponents they have been going through lately is doing nothing but sharpening the Rangers’ game for the postseason. Recent games against Toronto, Florida, Carolina, Tampa, the Islanders, Winnipeg and, on Thursday, the NHL-leading Boston Bruins, are good for the Blueshirts, coach Peter Laviolette said.

“I think this is a good thing to be playing these games down the stretch,’’ Laviolette said after his team beat the Bruins, 5-2, at TD Garden. “Florida is coming again [Saturday]. And then you’ve got tough games with Philly and Colorado on the docket as well. So this is perfect for us. We’re in games right now that can help us, I think.’’

Artemi Panarin had a hat trick and Adam Fox’s career-high 13th goal of the season at 3:57 of the third period (40 seconds after the Bruins’ Justin Brazeau had tied it at 2-2) ended up being the game-winner as the Rangers swept the three-game season series with Boston.

Jonathan Quick had 24 saves to earn his 391st victory, which tied him with Ryan Miller for the most wins by an American-born goalie. “It means I’ve played with a lot of good players over the years,’’ Quick said. “It takes a lot to win one game, right? You need coaching, and four lines, six ‘D’ . . . and so I’ve been fortunate to play with a lot of great players. I’m grateful for the work they put in to allow me to achieve that.’’

The Rangers (46-20-4, 96 points) pulled within one point of the Bruins (41-15-15, 97 points) in the race for first overall in the league standings. It also kept them two points ahead of Carolina in the battle for first place in the Metropolitan Division, as the Hurricanes earned an overtime win over Philadelphia.

The Rangers got off to a quick start, recording the first four shots on goal of the game. But Boston, aided by a couple of power plays, slowly began to take control of the first period. They didn’t score on either man advantage, but they did score right after the first one ended, taking a 1-0 lead on a goal by Jake DeBrusk at 8:04.

The Rangers managed to get out of the period without any further damage despite being outshot 14-9. A lot of that was due to the solid work of Quick.

“There were too many good looks [for Boston], but . . . that’s going to happen at times, and Quickie was on point tonight,’’ Laviolette said. “He made some brilliant saves in that first period.’’

The Rangers tied it on Panarin’s first goal at 7:58 of the second. Braden Schneider started the play when he skated the puck from behind his own goal line out of the zone, got all the way to the lower right circle of the offensive zone and threw the puck into the slot area, where two Bruins defenders swiped at it. Danton Heinen inadvertently knocked the puck onto the stick of Panarin, who shot it between the pads of Boston goalie Jeremy Swayman.

Panarin struck again in the final minute of the period. Alex Wennberg hounded defenseman Hampus Lindholm as he tried to go behind the net, and Lindholm turned it over to Panarin just outside the left goalpost. Panarin tried to send a cross-crease pass to Wennberg, but DeBrusk dived to try and block it, and the puck deflected off him and got past Swayman to put the Rangers up 2-1 with 34.7 seconds left.

After Brazeau and Fox exchanged goals early in the third, Mika Zibanejad scored an empty-net goal with 2:03 left to make it 4-2. Panarin completed his hat trick with an empty-netter with 51.6 seconds left.

“I think we look like a pretty good team now,’’ said Panarin, who has 41 goals and a career-high 97 points. “Obviously, we’re playing well, especially when you can win against such great opponents.’’

More Rangers

Newsday LogoSUBSCRIBEUnlimited Digital AccessOnly 25¢for 5 months
ACT NOWSALE ENDS SOON | CANCEL ANYTIME