In the Nets’ season-opening loss in Detroit, Caris LeVert saw a career night end with a turnover on the pivotal last-minute play. When he got another chance in Friday’s home opener, he capped another career-night with the game-winner.

The Nets came from behind to pull out a 107-105 win over the Knicks before a sellout crowd of 17,732 at Barclays Center, and they did it behind LeVert. He snapped the Nets’ four-game skid against their rivals and showed why he’s rapidly becoming their best player.

LeVert had a career-high 28 points, six rebounds and five assists. He shrugged off a nasty flagrant foul by Enes Kanter and hit a tough shot off the glass with one second left to snap a 105-all tie. It gave the Nets the lead for good, and his defense on Tim Hardaway Jr. — harassing his fellow former Michigan alumni into a last-ditch miss — helped seal the win.

“He did a heck of a job on both ends of the floor, especially at the end. He made Hardaway work for his shots. He was our leader,” Nets coach Kenny Atkinson said. “After the game he said coach I owed you one from the Detroit game.Great game-winner. That was a heck of a finish at the end.”

The opener at Detroit had been two days earlier, when LeVert poured in a then-career high 27 points. But when he drove into traffic with just 7.8 second left, he got stripped for the turnover that decided the contest. But Friday, he finished.

“The kid is a big-time talent. He had a really good game,” Knicks coach David Fizdale said of LeVert, whom the Nets were loath to put in any potential deal for the Timberwolves’ Jimmy Butler. “He’s a good player. He’s an explosive athlete. He can really put the ball on the floor. His 3-ball has improved tremendously. He’s a competitor. … That kid can play, and I think he’s going to have a breakout year this year.”

The Nets also broke a skid against the Knicks, beating their crosstown rivals for the first time since March 16, 2017.

“We didn’t beat them last year,” LeVert said. “We knew that coming into [Friday], so we definitely wanted to get that revenge, start the season off the right way at home.”

The Nets (1-1) saw Hardaway and Kanter each score a game-high 29 points. But they finally got the job done on the glass against the Knicks, outrebounding them 55-36. Jarrett Allen had 15 points, 11 rebounds and four blocks.

Considering the Nets forced just three turnovers all night and allowed 24 more shots, they had to be near-perfect.

Spencer Dinwiddie, who had proclaimed the Nets the better team in the New York, hit a 3-pointer to put them up 54-42 late in the first half. They took a 57-50 lead into the locker room, and were still leading 65-55 after D’Angelo Russell (15 points, six assists, five rebounds) hit a straight-ahead 3-pointer.

That’s when they watched the Knicks reel off 11 straight points. Hardaway hit a 3-pointer and shimmied up the court after giving the Knicks a 66-65 lead. The run hit 19-4 after lottery pick Kevin Knox drilled a right-wing 3 for a 74-69 edge.

The Nets still trailed 80-74 after a Allonzo Trier basket, but fired back with an 8-0 run to go up by a basket. When Fizadale pulled a dominant Kanter for Lance Thomas, LeVert immediately drilled a corner 3.

LeVert’s free throws put the Nets ahead 105-102 with 1:13 to play. They lost the lead on a Kanter and-one, but LeVert gave it back in the end.

“If he can hit that 3-point shot off pick-and-rolls, he’s going to be unstoppable at guard,” Jared Dudley said. “It’s going to be nice to see him develop.”