HOUSTON — James Harden was glorious. But the Nets were victorious.

In a season of wild wins for the Nets, this was the wildest. They rallied from a double-digit deficit in the third quarter, climbed out of a seven-point hole in overtime. And when it was over, they had pulled out a 145-142 overtime rally to stun the Rockets and a sellout Toyota Center crowd of 18,055.

“Great basketball game. Great basketball team. Two teams fighting, played their hearts out. We just made one more play than they did,” Nets coach Kenny Atkinson said. “We’ve had it go the other way in the beginning of the season, so we’re starting to get some payback.”

The Nets had to overcome a game-high 58 points from Harden (who also had 10 rebounds and six assists) and an NBA-record 70 3-point attempts from the Rockets (who fell to 25-19). But they did just that, thanks to two late rallies, a big night from Jarrett Allen (20 points, a career-high 24 boards and three blocks), and clutch shooting from Spencer Dinwiddie.

“The man had [58] and we won. That’s big-time for a young group,” said Dinwiddie, who came off the bench to lead the Nets with 33 points, added 10 assists and scored 16 points in the final minute of regulation and overtime.

“Just fantastic. He was unbelievable,” Atkinson said. “We got to get in a new play: It’s called ‘Everybody get out of the way.’ Really, it was one-four flat and give him space to roam. We had to play quick, no plays. He thrives in that situation.”

Thrive is an understatement.

The Nets trailed 118-105 after Harden’s step-back 3 with 4:01 left in regulation, and were still 128-122 with only 28.6 seconds remaining — but then Dinwiddie caught fire. He hit three 3-pointers in the final half-minute of regulation, the last with 8.4 seconds left to knot the score at 131-131.

After failing to slow Harden with man-to-man, zones and denials, and even picking him up fullcourt, the desperate Nets starting doubling the Rockets All-Star 35 or 40 feet from the basket down the stretch. That finally forced him to miss and allowed then to send the game into overtime.

“I’m speechless how good he is. It changed everything, how you coach. We’re doing things we’ve never done before,” Atkinson said. “He’s changing the way the game is played. He’s revolutionary.”

But the Nets overcame Harden. They got into overtime, and that’s when Dinwiddie led another rally.

After the Nets fell behind 142-135 on a James Nunnally corner 3-pointer with 1:28 left in the extra period, the Nets closed on a 10-0 run. And it was Dinwiddie who drove at PJ Tucker to earn a three-point play, and completed it for a 143-142 lead with 28 seconds left — a lead the Nets never surrendered.

“Spence is Spence. He shows up at the big moments,” said DeMarre Carroll, who had 22 points. “He’s the head and [D’Angelo Russell] is the head. Those are our team heads of the snake. … We go as far as those two take us.”

So far they have carried the Nets to a 15-5 run since Dec. 7, just a half-game behind the red-hot Pacers for the best record in the NBA during that span. The Nets (23-23) also pulled even with the Heat for the sixth seed in the Eastern Conference, and are up to .500 this late in a season for the first time since 2012-13.

“That’s big-time progress,” Atkinson said.

“The way our seasons have gone in the past, to be that caliber of team and be in the playoff race — and beat one of the best teams in the league and arguably the best player in the league when he basically gave us 60 points — that’s a testament to our group,” Dinwiddie said.

“One of our core principles is resiliency, and we showed that [Wednesday]. We showed that really all season. We’ve been decimated by injuries. … We found a way to pull together and grind out wins and really turn our season around.”