SAN JOSE, Calif. — It was a small moment on a big night, but it meant a lot.

After the Rangers had beaten the Sharks, 6-5, on Thursday night at SAP Center, after they had saved their four-game road trip from being winless, after they had allowed themselves to go into the All-Star break with a little bit of good feeling, Henrik Lundqvist walked over and gave J.T. Miller a big, hearty handshake.

A few words of encouragement from the leader of the team in a relatively restrained locker room said it all. Miller redeemed himself after an unforgettable benching Tuesday, and so had the Rangers. They did not let a mostly good effort go unrewarded. They found a way to have just enough to overcome their nightly mistakes.

And the performance allowed Miller to smile, and allowed his team to take a big breath that is going to taste quite a bit sweeter over the next few days off.

“It’s amazing sometimes, just sit back and look at how simple you have to play sometimes and that’s when the ice really seems to open up,” Miller said after he registered the game-sealing goal with 1:50 left in regulation to make it 6-4 while adding two assists. This was just two days after coach Alain Vigneault found it necessary to staple Miller to the bench for the final two periods of a 6-3 loss to the Ducks in Anaheim.

Brady Skjei scores a goal on Aaron Dell.AP

“It’s when you stop moving your feet and trying to make something out of nothing is when you get in trouble,” Miller said. “Just went back to trying to play my game and create a little room for us.”

Miller was part of the line that was the catalyst for the offensive outburst, with Mats Zuccarello and Kevin Hayes, the latter returning from a six-game absence because of a leg contusion. Hayes had a goal and an assist, while Zuccarello added to two assists to drive the much-needed scoring explosion.

“Tried to get in first on pucks, keep it simple,” Miller said. “Made some good plays to put it the back of the net.”

The Rangers (25-20-5) now can reset during this break without too much angst. They didn’t get the sharpest performance from backup goalie Ondrej Pavelec, who stopped 23-of-28 shots in his ninth start of the season as Lundqvist sat in preparation for the All-Star weekend. But it turned out that they didn’t need it against the Sharks (26-15-7), who are reeling from the knee injury to Joe Thornton.

“To be honest, I had nothing to do with the win,” Pavelec said. “The guys battled so hard, scored six goals. So it would be kind of a crime to lose the game with the six goals on the road.”

It almost was a crime, as Hayes’ goal 5:45 into the game quickly turned into a 2-1 deficit with tallies from Barclay Goodrow and Logan Couture. Jesper Fast tied it up, 2-2, but Couture scored again at 2:36 of the second to give the Sharks a 3-2 lead.

Then came the first goal of the season for captain Ryan McDonagh, followed up 72 seconds later by his second, that one on the power play to give his team a 4-3 lead. Another goal from the backend, a shorthanded tally off the shin-pad of Brady Skjei, made it 5-3 going into the third.

And San Jose came out in the third pushing, with Marc-Edouard Vlasic making it 5-4 at 10:51, which made things nervous until Miller scored at 18:10. Because it’s never easy for the Rangers, Tomas Hertl scored with 49.7 seconds remaining in regulation to make it 6-5.

But it wasn’t enough. When the horn sounded, it was a big sigh of relief for the Blueshirts. And no one felt it more than Miller.

“Team needed that,” Miller said. “Good way to cap it off and feel good going into the break.”