SAN JOSE, Calif. — The Rangers were on the cusp of crawling home from their California road trip with some real questions about their readiness for the playoffs.

But in a startling turnaround, trailing by two goals late in the second period, the Rangers scored three goals in 5:07 — two on the power play — to go ahead by one before giving it up late in regulation and in overtime in a 5-4 loss to the San Jose Sharks on Tuesday night at SAP Center.

But the point was enough to clinch a postseason berth for the Rangers.

Chris Tierney’s second goal of the game tied it with 2:15 left in regulation, and Brent Burns got the winner on a power play 3:10 into overtime.

“For 39 minutes, we didn’t show up, we didn’t make a play, we didn’t compete, we didn’t execute,” coach Alain Vigneault said. “Then we got a power-play opportunity and after that we played a good third period. And at the end of the night, we got a checkmark [in the standings]. For us to get into the playoffs, it’s hard. It’s a testament to this group how hard they prepared during the season, but we’re in and that’s the first objective of any team.”

Trailing 3-1 but on the power play when Sharks forward Patrick Marleau went off for interference with 1:31 left in the second period, Mats Zuccarello found Derek Stepan open at the backdoor with 22.4 seconds left and Jesper Fast tied the game at 1:24 of the third, tipping Brady Skjei’s shot past goaltender Martin Jones. It was the rookie defenseman’s third assist of the game.

advertisement | advertise on newsday

Then on a four-on-three, J.T. Miller wired a shot past Jones — his second goal of the game — for the lead.

All the Rangers needed was a point against the Sharks, who had lost six games in a row and were desperate. Instead, the Blueshirts went 1-1-1 on this California trip and have 97 points with five games left in the regular season.

Henrik Lundqvist, who made 30 saves, did not seem like himself from the outset in his second game back after missing eight with a hip muscle strain, and the Rangers didn’t help him. They didn’t have the puck from the opening faceoff, couldn’t clear their zone and Jannik Hansen batted in a loose puck in front at 1:44. The Sharks had allowed the first goal in the previous seven games.

At the 10-minute mark, Jones blockered away a wrister from Stepan charging down the middle, only the second shot on goal in the first half of the period. But Miller snapped in his 21st from the right dot with 6:30 left in the first to pull the Rangers into a 1-1 tie after Matt Puempel dug the puck from the wall near the benches.

Brendan Smith was whistled for interference and Michael Grabner, who has been snakebit on breakaways, tried a backhander that Jones stopped with his left pad. But the damage came with the Sharks shorthanded with Mikkel Boedker in the box for tripping Nick Holden at 16:09.

Although several Rangers were behind the net on the power play, they couldn’t get the puck, which Marc-Edouard Vlasic sent to Melker Karlsson, who came all the way down the left side from his own zone, and fired stickside past Lundqvist for a 2-1 lead at 18:01. It was the second goal on nine shots against Lundqvist, who had been on the wrong side of five goals in Anaheim on Sunday.

“I’m just extremely disappointed right now,” Lundqvist said. “I’m glad we’re in, but I want to get the job done, I want to get a win. We found a way to lose this one, but we played really well in the third. In the second period, I was exhausted, I was moving a lot. Not necessarily how I wanted to move, it was a battle. In the end, I’m looking to get structure to my game.”

As Vigneault frantically changed lines and defense pairs, the Rangers continually tried to stickhandle their way out of the zone, were getting caught from behind on transition in midice, and couldn’t get to the net or keep the Sharks away from Lundqvist.

Joe Pavelski’s wrister clanged off the post over Lundqvist’s glove with 11:35 left in the second, and the Rangers were teetering. With a scramble in front and Jimmy Vesey unable to clear a bouncing puck, Lundqvist kicked out a shot, but Tierney slipped to the crease and scored unassisted at 11:38.

But the unexpected rally helped lift the Blueshirts into the playoffs for the seventh consecutive season and released a lot of pent-up pressure.

advertisement | advertise on newsday

“Right now, we need one point to get the first wild-card spot,” Vigneault said. “In the third period, I went down to three lines and some guys I thought stepped up.”

Chris Kreider said: “We have to use the third period as a template. We’re pleased with the point, but the process has to be better. It can’t be just a handful of guys on a different night, it needs to be everyone.”