Rangers right wing Kaapo Kakko follows through on his shot...

Rangers right wing Kaapo Kakko follows through on his shot to score behind Montreal Canadiens goaltender Sam Montembeault for the winning goal late in the third period of an NHL hockey game at Madison Square Garden on Saturday, Nov. 30, 2024. Credit: Kathleen Malone-Van Dyke

The Rangers were eager to turn the page after Friday’s disheartening loss to the Flyers in Philadelphia. They also were desperate to end their five-game losing streak in any way possible. How didn’t matter, and against whom didn’t matter.

So even though they blew a two-goal lead in the third period Saturday and needed a power-play goal in the final minute of regulation just to get past the last-place Montreal Canadiens, they most certainly will take it.

“It’s kind of not our best performance,’’ Artemi Panarin said after Kaapo Kakko’s goal with 24 seconds left delivered a 4-3 victory. “But ... right now, we need something. So it doesn’t matter [how we] win, we’re happy with two points right now and then we’ll try to step forward.’’

Jonathan Quick made 25 saves and earned career win No. 398. He is 5-1 this season.

Playing in the second game of a back-to-back, the Rangers (13-9-1), who were boosted by the return of forwards Chris Kreider (back spasms, three games missed) and Filip Chytil (upper body, seven games missed), avoided the sort of poor first period that had been killing them.

The Rangers took a 2-1 lead in the first and led 3-1 after the second on the strength of power-play goals by Panarin and Mika Zibanejad and an even-strength goal by Vincent Trocheck at the end of the first period.

But Montreal’s Cole Caufield got free in the left circle and snapped a shot past Quick at 4:16 of the third. Nick Suzuki beat a diving Braden Schneider to the back post and tapped in a feed from Mike Matheson to tie it at 3-3 at 14:07, stunning the Rangers and the Garden crowd.

After that, the Canadiens (8-12-3) had a flurry or two that made it seem as if they might win the game in regulation time.

But Kirby Dach got his stick up in Zibanejad’s face and drew blood, picking up a four-minute high-sticking penalty with 2:40 left. The red-hot Will Cuylle played a pass from the slot to Kakko below the right-wing circle, and he smacked home the winner before Canadiens goalie Sam Montembeault could get across and cover the open net.

“Sometimes when you’re trying to get out of [a losing streak], that first win that you get might not be the prettiest,’’ coach Peter Laviolette said. “And it wasn’t tonight.

“We’ve got to draw on the positives of what we were able to do from the physicality, the start, the fact that we [blew a lead] but we came back and won it, the specialty teams factoring into it. I think you just pull all those things out of it and just continue to work your way out.’’

Largely, the Rangers won the game because of their special teams. The power play, which had gone eight straight games without scoring, connected three times in six opportunities and the penalty kill blanked Montreal on three tries.

To a man, the Rangers credited a first-period fight between captain Jacob Trouba and Montreal forward Josh Anderson with helping them get off to a better start to the game.

“I think that was something we needed,’’ Kakko said. “I mean, we’ve been pretty bad lately ... you’ve got to do something. And he’s our captain, he’s our leader. So that’s something that got the guys going. And I think that was a good start.’’

With Kreider and Chytil back in the lineup, Laviolette took the opportunity to rearrange his forward lines, making what looked like some pretty drastic changes. Chytil was put on a new top line, between Panarin and Cuylle, the team’s top two scorers, and Zibanejad, usually the No. 1 center, was dropped to the third line between Kreider and Kakko.

Chytil, who has been skating with the team for more than a week, didn’t want to reveal too many details of the injury he suffered in an on-ice collision with teammate K’Andre Miller against San Jose, but he said he was confident he was good enough to play.

“I know my body. I know what’s going on, even with my head, and I know what I went through last year as well,’’ he said. “And it’s been hard moments. But you know, I say all the time, I’m staying positive in every situation ... and [when there] is the opportunity to be back and my whole body feels great, I jump back in. And I’m happy that after two weeks, I could play today.’’