Rangers goaltender Jaroslav Halak reacts after Red Wings right wing...

Rangers goaltender Jaroslav Halak reacts after Red Wings right wing Matt Luff scored in the second period of an NHL game at Madison Square Garden on Sunday. Credit: Kathleen Malone-Van Dyke

Through the first month of the season, Gerard Gallant has been relatively patient with the Rangers, saying positive things about his group, even after losses.

But the second-year coach ran out of patience in Sunday’s game at Madison Square Garden against the Detroit Red Wings.

Only 25¢ for 5 months

Unlimited Digital Access. Cancel anytime.

Already a subscriber?

Through the first month of the season, Gerard Gallant has been relatively patient with the Rangers, saying positive things about his group, even after losses.

But the second-year coach ran out of patience in Sunday’s game at Madison Square Garden against the Detroit Red Wings.

Unhappy with his team’s performance in the second period, Gallant made some drastic changes in his lineup in the third period, blowing up his forward lines and dropping first-line left wing Chris Kreider to the fourth line.

The changes seemed to spark the Rangers in the third, but it wasn’t enough to save them from a disappointing defeat. The Red Wings got a power-play goal from Dominik Kubalik in overtime to complete a comeback in a 3-2 win over the Blueshirts.

K’Andre Miller was called for holding the stick with 3:16 remaining in overtime and Kubalik got behind goaltender Jaroslav Halak and deflected in a shot by David Perron at 2:43 for Detroit (7-3-2).

The Rangers (6-4-3) led 2-0 after the first period on goals from Kaapo Kakko and Mika Zibanejad (on the power play). But Detroit dominated the second period and tied it on goals by Matt Luff and Pius Suter.

“The second period, I think, got away from us,’’ Rangers defenseman Jacob Trouba said. “That’s all it takes. We’ve got to find a way to play a full game. It’s something we’ve got to find a way to do. I don’t think we’ve put a real consistent 60 minutes together very often this season. That’s what it takes to win in this league.’’

When the third period began, Gallant made changes to all of his lines. He said he had been contemplating making changes for a while.

“I just tried to shake things up a little bit, see if we can wake a few guys up,’’ he said.

When asked about dropping Kreider, who scored 52 goals last season but hasn’t been on the same kind of goal-scoring pace this season, Gallant said, “He deserved to be where he was at. He wasn’t alone.’’

Gallant put Artemi Panarin on Zibanejad’s left wing and put Jimmy Vesey and Sammy Blais on either side of second-line center Vincent Trocheck. Alexis Lafreniere, usually the second-line right wing, dropped down to left wing on the third line next to Filip Chytil — who returned to the lineup after missing six games with a suspected concussion — and Barclay Goodrow.

Kreider ended up on the left of Ryan Carpenter and Julien Gauthier. Defenseman Zac Jones also was benched in the period. He played one shift in the third.

The Rangers began to generate more scoring chances and outshot Detroit 12-8 in the third period. But Halak, who made 33 saves, was called on to bail out his teammates several times. He saved a clean breakaway by Kubalik late in the period and, in the final minute of regulation, moved from left to right to get a blocker on a one-timer from Filip Hronek.

“He was great,’’ Gallant said. “He gave us a chance to get that point for sure. He was outstanding.’’

Halak (0-3-1) was sharp, and had to be to keep it tied late.

The Rangers were outshot 14-11 in the first period, 10-6 in the second and 36-29 in the game, and Halak kept them in it. But when asked if he thought this was his finest game of the season, he downplayed that.

“I mean, we didn’t get a win,’’ he said. “It’s about winning, and we lost a game again. So you know, it’s nice to get one point, but we need to get the extra one.’’