Playing like a team desperate to regain some traction, the Rangers opened a three-game homestand on Tuesday with a 6-2 victory over the NHL-leading Dallas Stars.

“We finally competed the right way for 60 minutes and it’s definitely a confidence-builder,” said Derek Stepan, who scored two goals — the opening tally at 1:56 and a shorthander early in the third period — to pace the Blueshirts, who won for just the third time in eight games. “But I’ll be honest, come tomorrow, it doesn’t mean anything, we have to have the right mind-set for another very good team coming in [Washington] on Saturday.”

For one evening the Rangers (22-14-4) could bask in the feeling that they regained an element of what made them so successful early in the season and through the past two years.

“It was our mind-set before the game. Right from the beginning, I think they knew it wasn’t going to be easy to break through and score,” Marc Staal said. “We just kept wearing them down. In the last few games, we’ve kept their [opponents’] shot totals down, our forwards came back to stop their rushes, and we’ve scored some goals when we had the opportunities. We know the way we have to play defensively and we did that tonight.’’

Indeed, the Rangers pressured the Stars as soon as the puck dropped, won battles on the boards, went to the net, used the body and scored timely goals, one each from Keith Yandle, Derick Brassard, Viktor Stalberg and Jayson Megna, in his Broadway debut. Even the coaching staff was sharp, arguing that a third-period goal that would have cut the lead to 5-3 was offside and winning the challenge. Rick Nash was huge as well, playing like a classic power forward, with three assists.

The Stars (28-10-4), who had lost two straight to the Islanders and Devils, came to town with the most third-period goals in the league, so they remained dangerous even after Brassard’s shot that Antti Niemi only got a piece of trickled over the goal line at 17:23 of the second for a 3-1 advantage.

advertisement | advertise on newsday

Just a few minutes earlier, Jamie Benn had came close to tying the score at 2, but Staal’s check in the crease knocked the league’s second-leading scorer to the ice so that his backhander slid off the post and away.

When Stepan scored his second at 4:55 of the third — the Rangers first shorthanded tally of the season in the 40th game — and Stalberg banged in a loose puck at 7:50, it looked as if the Rangers just had to hold the fort at 5-1.

But 50 seconds later, Antoine Roussel deposited a cross-crease pass past Henrik Lundqvist to force the Rangers to work to close it out. With 6:54 to go, it appeared to be 5-3 on a give-and-go finished by Valeri Nischushkin. But Rangers assistant coach Ulf Samuelsson insisted that Jason Spezza was offside on the play before the goal. Coach Alain Vigneault challenged the play and the goal was waved off.

That proved to be the final turning point, as moments later, Megna, playing for Chris Kreider (hand injury) completed a 2- on-1 from Nash for his first goal as a Ranger and a two-point night.

In the first period, with the score tied at 1, Yandle’s second goal of the season had provided the first game-changer, when his long wrister went through Kevin Hayes’ screen 18 seconds after the Stars had tied the game at 1 at 13:50. Lundqvist allowed a soft shot from John Klingberg to slide under his pads.

“When you are able to answer back after a bad goal like that, it’s big for the team,” said Lundqvist, who finished with 21 saves. “We were back on track right away, no thinking.’’

Stepan opened the scoring at 1:56 with his first goal since Nov. 23 and at the first intermission, the Rangers were outshooting the Stars 14-6 and didn’t allow a shot on goal until Lundqvist gloved Benn’s wrister at 11:41. “I felt like we were on our toes. We had some extra jump,” said Lundqvist. “I think we played with poise and awareness . . . hopefully we’re moving in the right direction.”