For two periods Thursday night, the Rangers had a hard time coping with the Edmonton Oilers, a team that has mirror-image speed and quickness.

After twice falling behind by a goal, the Blueshirts responded to come away tied after 40 minutes. Tactically, however, something had to change. Adjustments had to be made.

“We watched some clips in between periods,” Rangers defenseman Marc Staal said. “They had a tight gap at the blue line and we tried to force plays through that. They’re probably one of the best teams we’ve played so far as far as their speed. They forced us to do some things with the puck that we normally don’t do. Once we started getting it behind them, we started showing our speed.”

And then the Rangers began scoring, as they have all season, en route to a 5-3 victory at Madison Square Garden.

After they fell behind 3-2 at 8:49 of the third period on a goal by Adam Larsson, Jesper Fast redirected Brandon Pirri’s shot past Cam Talbot at 9:31 to tie the score for the third time.

advertisement | advertise on newsday

Then Rick Nash scored on a rebound at 18:39 for his sixth of the season to give the Blueshirts a lead for the first time, and J.T. Miller banked a billiards-style shot off the boards and into an empty net 17 seconds later.

“We knew what we had to do,” Nash said. “We just couldn’t get a handle on the puck. When we went deep, we had success.”

In the end, the Rangers (8-3) concluded a sweep of the three-game homestand and won for the sixth time in the last seven games. The up-and-coming Oilers fell to 7-3-1, but they are a team to be reckoned with.

“At the start, we were kind of surprised how fast they were,” said Kevin Hayes, who scored his fourth goal of the season in the first period and added two assists. “It was new for us.”

In the second period, the Rangers responded for the second time when Michael Grabner, battling in front, edged away from former Devils defenseman Adam Larsson in front of Talbot and tied the score at 2 by tapping in the rebound of Miller’s sharp-angle shot at 15:46.

Talbot (26 saves) is a former Rangers goaltender who was making his first appearance at the Garden since being traded for three prospects at the 2015 entry draft.

When Ryan McDonagh’s one-timer was blocked at the blue line and he made a diving attempt to try to prevent a breakaway, he tripped Derek Stepan, setting up an odd-man rush by the Oilers. In the developing two-on-one, Jesse Puljujarvi waited, Dan Girardi snow-angeled and Puljujarvi slipped a pass to Patrick Maroon on what essentially was a two-on-none, with Maroon tucking the puck around Henrik Lundqvist at 10:28 to give the Oilers a 2-1 lead.

Oilers center Ryan Nugent-Hopkins had opened the scoring at 6:36 of the first period on a power play with Fast in the box for a high-sticking double minor that drew blood on Leon Draisaitl.

Hayes’ fourth goal tied it at 1-1. After Brady Skjei’s long shot bounced off Talbot, Grabner scooped it in front and fed Hayes, who swept the puck past Talbot at 8:34.

“We made it a little easy on them today for two periods, feeding into their transition game,” Grabner said, “but at the end of the day, the wins count.”