Rangers left wing Artemi Panarin reacts after scoring a power-play...

Rangers left wing Artemi Panarin reacts after scoring a power-play goal against the Sharks in the first period of an NHL game at Madison Square Garden on Sunday. Credit: Kathleen Malone-Van Dyke

The Rangers showed up at their home rink as the proud owners of the most wins in the NHL. The Sharks showed up as the not-so-proud owners of the most losses to go with the fewest wins. And they had done the league’s worst road work to date.

Yes, San Jose had been playing better after a dreadful start. And yes, the Rangers were playing the second game of a back-to-back Sunday night with a plane trip in between after Saturday’s win in Nashville. But this really shouldn’t have been a slippery game for them on Garden ice.

Yet despite a hat trick and an assist by Artemi Panarin, it was a struggle. The Rangers let a three-goal third-period lead slip to one before holding on for a 6-5 victory.

“I think it’s good to take the two points for sure,” Panarin said. “But we have to play more disciplined, more focused with the puck.”

It was the 3,000th regular-season win in franchise history, making the Rangers one of five teams to reach that number. It also was their third straight victory, sixth in seven games and 10th in 12. They are on a 16-2-1 run and improved to 18-4-1.

After a 0-10-1 start, the Sharks, led by former Rangers coach David Quinn, are 6-17-2 and 1-11 on the road.

When the Rangers trailed 2-0 after the first period on Saturday, coach Peter Laviolette woke them up between periods and changed up his lines. The Blueshirts rallied for a 4-3 victory over the Predators.

“It served a purpose,” Laviolette said.

He reverted to the original lines for the most part to start this game. The big change was moving right wing Jonny Brodzinski to the first line with Mika Zibanejad and Chris Kreider. Brodzinski had two assists for the second straight game.

“We used our speed well,” he said.

With 3:57 left in the second period, rookie left wing Will Cuylle took a feed from Nick Bonino, broke in on Mackenzie Blackwood and scored to give the Rangers a 4-3 lead.

Panarin, who scored twice in the first period, made it a two-goal game with his third of the night and 15th of the season 4:41 into the final period. The left wing stuffed in a rebound, leading to a sea of hats on the ice.

K’Andre Miller scored with 6:56 remaining off an assist from Panarin to extend the advantage to 6-3. But Fabian Zetterlund beat Jonathan Quick with 5:22 remaining and Alexander Barabanov cut it to 6-5 with 4:10 left.

“We can definitely clean some stuff up, especially defensively,” Brodzinski said.

The Blueshirts fell behind 1-0 just 3:50 into the first period after a breakaway goal by former Ranger Anthony Duclair, but Panarin tied it with a power-play goal at 8:44.

Ryan Carpenter put San Jose ahead again at 12:21, but Panarin scored on a rebound 34 seconds later to tie it at 2-2.

“Maybe I should change my game because I go to the net twice in my life and both work,” Panarin quipped, referring to his second and third goals.

The Rangers took a 3-2 lead with 3:18 left in the first period when Kreider set up Zibanejad. Jacob MacDonald tied it at 9:16 of the second before the Rangers scored the next three goals.

“We were thinking 6-3, it was over, and it wasn’t over,” Laviolette said. “ . . . But at the end of the day, the guys fought really hard I think today under the circumstances and got ourselves a win.”

More Rangers

Newsday LogoSUBSCRIBEUnlimited Digital AccessOnly 25¢for 5 months