The San Jose Sharks did almost everything they wanted to do in the first period of Thursday’s game against the New York Rangers.

Then, as the second period wore on, they began to do the exact opposite.

The Sharks scored first at Madison Square Garden but couldn’t overcome their mistakes in the latter half of the second, allowing three unanswered goals in less than five minutes in a frustrating 3-2 loss to the Rangers in the third game of a four-game road trip.

“We just got away from our game,” Sharks forward Barclay Goodrow said.

Defenseman Timothy Liljegren scored his first goal of the season at the 2:51 mark of the first period to give the Sharks a 1-0 lead. But after some missed opportunities, the Sharks became their own worst enemy later in the second, allowing goals to Mika Zibanejad, Jimmy Vesey, and Vincent Trocheck to fall behind 3-1.

On Zibanejad’s tying goal at the 11:41 mark of the second period, Sharks goalie Mackenzie Blackwood backhanded a pass behind the net along the boards intended for Cody Ceci. But Chris Kreider retrieved it instead, and two seconds later, Zibanejad tipped a pass from Adam Fox past Blackwood for his third goal of the season.

The Sharks were caught puck-watching on the next two goals they allowed, particularly on Trocheck’s goal at the 16:21 mark of the second. After the Rangers retrieved the puck in their zone, it only took three passes before Artemi Panarin found Trocheck open inside the Sharks’ zone, as he redirected the pass past Blackwood for a 3-1 Rangers lead.

The Sharks, who appeared to lack communication on the play, were outshot 16-6 in the second period and 11-4 through the first 10 minutes of the third.

With the extra attacker out, Fabian Zetterlund scored a power-play goal with 26 seconds left in regulation time to cut the Rangers lead to 3-2, but the Sharks could not find the equalizer.

“We really came out and did (some) good things,” Sharks center Alexander Wennberg said. “We kept the puck down low and were creating chances. Did a lot of good things in this game. There are parts of it that you want to learn from. But we made a push at the end. Obviously, it wasn’t enough.”

Blackwood finished with 32 saves as the Sharks fell to 1-1-1 on this road trip, which ends Saturday night in Pittsburgh.

The Sharks also announced near the start of the third period that Nico Sturm had an upper-body injury and would not return.

The Sharks had chances at a second goal before Zetterlund scored. Still, they were either foiled by Rangers goalie and Vezina Trophy winner Igor Shesterkin or shot themselves in the foot, like in the second period when they failed to get a shot on goal on a 3-on-1 with Mikael Granlund, Zetterlund, and William Eklund.

Eklund also had a shot attempt ring off the post in the first period, and Goodrow missed the net on a shorthanded breakaway in the second.

Shesterkin finished with 25 saves.

The Sharks successfully challenged Fox’s goal at the 14:32 mark of the second period. It was determined that Trocheck, coming from behind the net, caused Blackwood to lose his stick, which impaired his ability to play his position. The Sharks are now 3 for 3 on coach’s challenges this season.

Blackwood was coming off a 44-save performance in the Sharks’ 1-0 win over the New Jersey Devils on Sunday, continuing a trend of solid play.

In his last six starts before Thursday, starting with an Oct. 23 start in San Jose against the Anaheim Ducks, Blackwood was 3-3-0 with a solid .927 save percentage. Among the 37 NHL goalies who have played in at least eight games this season, Blackwood, per moneypuck.com, was 13th in goals saved above expected per 60 minutes (.346) before playing the Rangers.

Before Thursday, Blackwood was 3-4-2 with a .910 save percentage.

Blackwood, a pending unrestricted free agent, had been 6-8-0 with a .887 save percentage in 15 career games against the Rangers.

NEW-LOOK POWER PLAY >> The Sharks tweaked their power play units for Thursday’s game, with Macklin Celebrini joining the second unit alongside Will Smith, Tyler Toffoli, Goodrow, and Liljegren. It marked the first time Celebrini and Smith, the Sharks’ top two rookie forwards, had been on the same power-play unit in an NHL regular season game.

The Sharks’ top power-play unit featured forwards Granlund, Eklund, Zetterlund, Alexander Wennberg, and defenseman Jack Thompson.

It did little to no good, as the Sharks went 0 for 2 with the man advantage.