New York Rangers defenseman Adam Fox and Dallas Stars center Oskar...

New York Rangers defenseman Adam Fox and Dallas Stars center Oskar Bäck, right, slam against the boards while chasing the puck in the first period on Friday. Credit: AP/Tony Gutierrez

DALLAS — In this long, frustrating stretch the Rangers have been in, one in which they keep making mistakes, their flaws keep getting exposed and they keep finding inventive ways to lose games, perhaps the one thing they’ve been able to count on, game in and game out, is their penalty kill.

On Friday night, their penalty kill was spectacular, blanking Dallas for 17 minutes of power-play time as the Rangers ended their losing streak at three games with a 3-1 victory over the Stars at American Airlines Center.

The Rangers salvaged the final game of their three-game road trip and won for only the fourth time in the last 15 games (4-11).

Reilly Smith and Vincent Trocheck — who made up the first forward duo on the penalty kill — each had a goal, with Smith’s coming while the Rangers were shorthanded, and goalie Igor Shesterkin made 41 saves to win for the first time since Dec. 11 in Buffalo.

“We ended up having to kill more penalties, obviously, than we would like to have to kill,’’ coach Peter Laviolette said. “But the penalty kill was awesome. They scored a [shorthanded] goal, and I thought they did a tremendous job. Shesty was great in net, but the penalty-killers were fantastic.’’

The Rangers’ penalty kill — which was tied for the best in the league with an 87.1% success rate and had 10 straight kills entering the game — snuffed all seven Stars power plays, including a five-minute major in the third period as the Blueshirts tried to protect a one-goal lead.

Chris Kreider, another penalty-killing forward, added an empty-net goal with 2:06 left.

“Seventeen minutes on the PK is pretty gritty, so the PK came up big tonight,’’ Trocheck said. “We can get a lot of momentum from our penalty kill when it’s playing like it was tonight. It needs to continue to do that.’’

The PK came up especially huge when Matt Rempe, called up Wednesday from AHL Hartford in the wake of the Kaapo Kakko trade, was given a five-minute major penalty and an automatic game misconduct for his elbow on Miro Heiskanen with 12:47 remaining in the game and the Rangers up 2-1.

Rempe had had an excellent game to that point, landing several huge hits and drawing three penalties against the Stars in the second period. But that penalty — which could lead to a suspension — put the team in a terrible spot.

“I thought he had a big impact on the game,’’ Laviolette said. “We’d like to stay away from the five-minute major, but he’s doing his best to hit bodies and make a difference in the game. Our guys really rallied around that as well.’’

It probably helped that the Stars’ Roope Hintz, who had scored the opening goal of the game at 1:46 of the first period, charged at Rempe. He and Rempe got matching roughing minors, which meant Hintz was unavailable for the first two minutes of the five-minute power play.

But still, five minutes of penalty-kill time — when the penalty isn’t over if the opponent scores a goal — was a daunting situation.

“It took everyone,’’ said Adam Fox, who played a team-high 27 minutes and 15 seconds. “It took a bunch of great saves by Shesty [and] we just battled, blocked shots for five minutes. You know, you’re keeping it quick and hard, and, oh, we did a great job there.’’

After a shaky first shift in which turnovers led to a couple of great scoring chances for Dallas, the Stars appeared to take an early lead. Jamie Benn fired a shot way wide that caromed off the back boards, and he got to the rebound first and jammed it past Shesterkin at 1:15.

The Rangers challenged the play, alleging the Stars had been offside entering the zone. The challenge was successful, so the goal came off the board.

But 31 seconds later, Hintz scored one that counted, and for the first half of the period, the Rangers looked in danger of getting blown out. But then Mika Zibanejad got called for a slashing penalty, and that turned out to be the start of the turnaround.

A drop pass from Jason Robertson skipped over the stick of point man Thomas Harley and into the neutral zone. Smith pounced on the puck, drove up the left side and beat Stars goalie Jake Oettinger at 10:44.

“The bench really fueled up after that,’’ Laviolette said. “You get down early, and to have to be on the penalty kill, the game can swing a different way pretty quick. Smitty getting in behind there and burying that just gave good life to the bench. Good juice.’’

Notes & quotes: Artemi Panarin returned to the lineup after missing two games with an upper-body injury. Defenseman Will Borgen, acquired in the Kakko trade, made his Rangers debut.