After scoring just one goal in their first four games at Madison Square Garden this season, the finally got their offense on track on their home ice Thursday night.

Taylor Raddysh’s second career hat trick matched one by San Jose’s young star Macklin Celebrini, but another young San Jose star, Will Smith, blasted home the winner at 1:38 of overtime, giving San Jose its first win of the season, 6-5, and leaving the Rangers oh-for-October at the Garden.

The Rangers have lost five in a row at home to start the season for the first time since 1943-44.

After Celebrini’s third goal of the game tied the score, 4-4 with 5.8 seconds left in the second period, Smith scored at 6:31, one second after a Sharks power play expired, to give San Jose a 5-4 lead.

But Raddysh tied the game at 11:50 when he came off the bench on a line change, took a pass from J.T. Miller in stride, and ripped a shot that may have ticked off the stick blade of defenseman Vincent Iorio before it flew over the glove of goalie Alex Nedeljkovic (22 saves).

The Rangers now head out on their longest road trip of the season, four games in Western Canada and Seattle, beginning with a game Sunday in Calgary.

Coming off a performance they weren’t proud of against Minnesota on Monday, the Rangers were certainly hoping a game against the winless Sharks might provide a nice sendoff for the trip.

Coach Mike Sullivan shook up his forward lines, flip-flopping Alexis Lafreniere and Will Cuylle, with Lafreniere going back with Artemi Panarin and Mika Zibanejad, and Cuylle going back with Miller and Conor Sheary. The coach also broke up the Adam Edstrom-Sam Carrick-Matt Rempe line, elevating Edstrom and Carrick to the third line, with Raddysh, and dropping Juuso Parssinen and rookie Noah Laba to the fourth line, to play with Rempe.

The Rangers, though, got off to a lousy start. They got pinned in their own end in the opening minutes, and eventually rookie Michael Misa passed the puck to Collin Graf behind the goal. Vladislav Gavrikov, who’d been stationed in front of the net, left that spot to go after Graf, but Zibanejad went after him, too. That left Adam Gaudette wide open at the back post, so when Graf spun away from the two Rangers and passed to Gaudette, it was easy pickings for him to beat Igor Shesterkin (18 saves) and make it 1-0 at 1:58.

Rempe fought ex-Ranger Ryan Reaves at 5:55, after Reaves dumped Parssinen. It was an entertaining fight, with both players landing plenty of blows, and Rempe ended up getting the better of Reaves when he got the Sharks player’s jersey up over his head and was able to land a couple extra punches.

But Rempe left the game after that with an upper-body injury, and Celebrini’s first goal, on the  power play, gave the Sharks a 2-0 lead at 6:17. Celebrini got credit for the goal that pinballed off the skates of Will Borgen and Matthew Robertson and got past Shesterkin.

Raddysh’s first goal, on a wrist shot from the blue line, probably should have been stopped by Nedelkjovic, but Celebrini’s second goal, with 9 seconds left in the period, made it 3-1 and prompted some boos as the Rangers left the ice for the intermission.

The Rangers turned it around in the second period, getting a power-play goal from Zibanejad at 4:04, and tying it on Parssinen’s goal at 6:47. Raddysh then gave them their first lead when he scored a shorthanded goal at 12:10 and at that point, the Rangers looked like they’d taken control of the game.

But Celebrini scored his third goal on a one-timer from the left circle to tie it, 4-4, with 5.8 seconds left in the period.

Colin Stephenson

Colin Stephenson covers the Rangers for Newsday. He has spent more than two decades covering the NHL and just about every sports team in the New York metropolitan area.