SAN JOSE >> It was hard to keep count of the number of times the Sharks were competitive against a quality opponent last month, only to lose in heartbreaking fashion.

The script has flipped in January.

Defenseman Cody Ceci scored with 24.2 seconds left in the third period to lift the Sharks to a 3-2 win over the New Jersey Devils on Saturday before an announced sellout crowd of 17,435 at SAP Center.

Ceci took a pass from Alexander Wennberg at the point and fired a shot that got past Devils goalie Jacob Markstrom for his third goal of the season as the Sharks put together back-to-back wins for the first time in just more than a month.

In December, the Sharks gave up the tying or winning goal in the final three minutes of the third period four times. It happened most recently against the Edmonton Oilers on Dec. 21, when the Sharks allowed a tying goal to Mattias Ekholm with 18 seconds left in regulation before losing 3-2 in overtime.

“We’ve been on the other side of it. Now, to come out on this side, it’s good for our group,” Ceci said. “Those games are tough when you lose them in the last minute, and then that much better when you win it last minute.”

Nikolai Kovalenko and Macklin Celebrini also scored for the Sharks, who beat a second straight playoff-caliber opponent and improved to 8-12-1 at home. San Jose also beat the Tampa Bay Lightning 2-1 on Thursday to snap an eight-game losing streak.

“I thought we started getting our identity going there early in the year and not getting the result, and now we’re starting to get rewarded for it these last two,” Sharks coach Ryan Warsofsky said. “Our guys are starting to see the recipe of how you need to play and compete.”

Goalie Yaroslav Askarov finished with 29 saves, improving his record with the Sharks this season to 3-2-2 with a .923 save percentage.

Askarov’s most critical save came with 2:40 left in the third period. Jack Hughes was driving toward the Sharks’ net when he had a shot attempt blocked by Timothy Liljegren, but the puck cane right to Ondrej Palat, who shot it into a backpedaling Askarov. The puck then slid just wide of the net.

“He’s been huge,” Ceci said of Askarov. “The saves, him playing the puck, he’s been awesome for us back there. I don’t think (the game) gets to that point without him.”

Celebrini gave the Sharks a 2-1 lead at the 1:53 mark of the third period.

Kovalenko scored his first goal with the Sharks at the 17:40 mark of the first period.

Eklund returned to the Sharks lineup on Saturday after missing the previous four games with an upper-body injury sustained in a Dec. 23 game against the Vancouver Canucks when defenseman Tyler Myers hit him.

Eklund, tied for second on the Sharks with 28 points in 37 games, played on a line Saturday with center Mikael Granlund and fellow winger Fabian Zetterlund. Against the Devils, the three players combined for nine shots on goal.

“Grandpa (Granlund) there can help them out a little bit,” Warsofsky said of the line with Eklund, 22, and Zetterlund, 25. “He takes him under their wing. He’s helping these two young players, who are still trying to figure out how to play consistently in this league, and I think Granlund’s done a great job of helping them individually.”