NEW YORK (AP) — Jeff Petry scored his second goal of the game in the final minute of the third period and Sam Montembeault made 24 saves as the Montreal Canadiens beat the playoff-bound New York Rangers 4-3 Wednesday night to snap a nine-game losing streak.

Petry scored his sixth of the season with 31 seconds remaining to put Montreal ahead for the fourth time and forge a victory for Martin St. Louis, the former Ranger who took over behind the Canadiens' bench in early February coaching for the first time at Madison Square Garden.

“We stopped the bleeding tonight, that’s for sure. It feels good,″ said St. Louis who helped the Rangers reach the Stanley Cup Finals in 2014 after he was acquired from Tampa Bay in a late-season trade. “I was joking because I have beaten all the teams that I played for — beat Calgary in Calgary, beat Tampa there and now beat New York ... I wish I played on more teams.”

Ryan Poehling and Mike Hoffman also scored for Montreal, which had lost nine straight in regulation since a 7-4 win at New Jersey on April 7. The Canadiens are 21-49-11 this season after reaching the Stanley Cup Final last year.

Ryan Reaves, Frank Vatrano and Ryan Strome scored for the Rangers, and Barclay Goodrow had two assists to establish a career high of 20 assists. Alexandar Georgiev finished with 20 saves.

“Nobody got hurt. That was a key thing tonight," Rangers coach Gerard Gallant said. ”We played pretty well overall and we got through the game.”

The Rangers trailed 2-1 after two periods before Vatrano tied it at 4:15 of the third. The 28-year-old forward, playing in his 400th NHL game got his 18th of the season and eighth since coming over in trade from Florida on March 16.

Hoffman scored with just under eight minutes left to give the Canadiens a 3-2 lead with his 14th of the season.

Strome tied the contest for the third time with a short-handed goal with 3:19 remaining, his 21st of the season and the eighth short-handed score by the Rangers this season.

The Rangers rested seven regulars including top goal-scorer Chris Kreider and points leader Artemi Panarin a night after losing at home to first-place Carolina, assuring New York would finish second in the Metropolitan Division.

“Did I want to win tonight, of course,'' Gallant added. ”But we can't move anyway."

Poehling opened the scoring with 1:15 remaining in the first with his ninth goal of the season. Michael Pezzetta and William Lagesson assisted.

Reaves tied it at 4:14 of the second with his fifth of the season. Patrik Nemeth and Kevin Rooney had assists.

The last-place Canadiens mustered only five shots in the second but went ahead on Petry’s goal with 9 seconds remaining in the period.

“I’m on my game when I’m skating, getting the puck and moving my feet,″ said the 34-year-old Petry, a veteran of 12 NHL seasons with Edmonton and Montreal. ”It’s been a long time coming to find that and build off of that for next year.”

The Rangers are in the playoffs for the first time since 2017 and will open at home early next week against Pittsburgh or Washington in the first round.

“We feel good about our group for sure. We had a really good year,'' Rangers forward Alexis Lafreniere said. ”We are excited to play some playoff hockey."

ROD GILBERT AWARD

Kreider received the first Rod Gilbert “Mr. Ranger” Award, given to the player “who best honors Rod’s legacy by exemplifying leadership qualities both on and off the ice and making a significant humanitarian contribution to his community.” Gilbert, the Hall-of-Fame right wing whose holds the franchise record for goals (406) and points (1,021), died at 80 last August.

Kreider has worked closely with the Garden of Dreams and Hockey Fights Cancer during his decade as a Ranger. Kreider, who has 52 goals this season, also won the Steven McDonald “Extra Effort” Award on Tuesday night. That award, named for the former NYPD detective shot and injured on the job in 1986, is given each season to a Ranger selected via fan voting who “goes above and beyond the call of duty.”

NOTES: The Rangers also scratched forwards Mika Zibanejad and Andrew Copp, and defensemen Adam Fox, Jacob Trouba and Ryan Lindgren. ... New York was also without injured forward Tyler Motte. ... The Canadiens scratched forwards Joel Armia, Paul Byron and Mathieu Perreault plus defensemen Justin Barron, Chris Wideman and Kale Clague, and goaltenders Carey Price and Jake Allen.

UP NEXT

Rangers: Host Washington on Friday night in the regular-season finale.

Canadiens: Host Florida on Friday night to close the season.