The Miami Heat continued their invincible recent form against the Sacramento Kings, with Dwayne Wade scoring 39 points and LeBron James with 40 points and a career high 16 dimes in the 141-129 win.

Ray Allen added 21, Chris Bosh finished with 15 and Chris Andersen had 10 for the Heat, who remained six games clear of second-place Indiana in the Eastern Conference standings.

Miami’s 12-game winning streak is the longest in the NBA and matches the second-longest in franchise history.

“Our ball club, we don’t get rattled, no matter what’s going on during the course of the game,” James said. “If it’s overtime, double-overtime, we find a way to win.”

Marcus Thornton scored 36 points for Sacramento, the most by any reserve in the NBA this season. DeMarcus Cousins finished with 24 points and 15 rebounds, Tyreke Evans added 26 points, John Salmons 15 and Isaiah Thomas 14 for the Kings.

James became the first NBA player to finish with at least 40 points and 16 assists since Kevin Johnson — now the mayor of Sacramento — had 42 and 17 for Phoenix against Denver on April 3, 1994.

“Even with a double-overtime game, those are video game numbers,” Heat coach Erik Spoelstra said, noting that he told Wade the same after his 19-for-28 shooting effort in 46 minutes.

And for the month, James finished 139 for 217 from the floor — 64.1 percent, by far the best of his career.

Kings coach Keith Smart said before the game that sometimes “great teams get a little bored with the regular season and they need something to get them going.”

The Heat didn’t seem to be bored by the second overtime.

After a late non-call that James wanted, he simply seemed mad.

James scored inside to open the second extra session, yelling “and one” at referees as his way of insisting he was fouled as well. But after one sensational sequence, the game was pretty much sealed.

Thornton had a chance to give the Kings the lead after a Heat turnover, but his shot at the rim was blocked by Wade, who came down and set up James for a 3-pointer — a five-point swing, in essence, and the Heat had a 131-127 lead. James scored again, then added two free throws and found Bosh for a dunk and 10-point lead with 1:29 remaining.

Sacramento lost its sixth straight and fell to 1-16 against Miami since March 2004.

“No matter what their record is, they made plays just like us. They gave everything they had and more,” James said.

The Heat missed key free throws late in both regulation and the first overtime — Wade missing a pair with 21 seconds left in the fourth, and James missed one of two with 29.3 seconds left in the opening extra session.

In the first OT, the Kings had a chance for the late lead and potentially the win, but Thomas had a layup blocked by Bosh, and Allen grabbed the rebound for the Heat with 5.7 seconds left.

Miami put the ball in Wade’s hands, and he found James near the basket. James’ shot missed, and he complained he was fouled by Salmons on the attempt. Referees disagreed with that, but after a lengthy review to determine possession, they awarded Miami the ball with 0.4 seconds remaining. It was much ado for nothing, as Bosh’s shot sailed long and the teams went to double overtime.

The game was tied at 92 midway through the fourth before Wade — with six points and an assist — led a 13-4 run that looked like it would give Miami breathing room. Miami was up 105-96, and still led 112-104 when James scored with 1:40 remaining.

Sacramento roared back, scoring the final eight points of regulation. Thornton hit a pair of 3-pointers, the second coming with 23 seconds left to get the Kings within 112-110. And after Wade missed a pair of free throws, Cousins grabbed an offensive rebound and laid it back with 8.5 seconds remaining to knot the game at 112-all.

Out of a timeout, the Heat went to Wade, whose step-back 20-footer bounced off the rim as time expired, sending it to overtime.

They were just getting started. And when it was over, the Heat streak survived.

“We’re coming together,” James said. “We’re doing it the right way. We’re executing offensively. We’re sharing the ball. And we’re not getting rattled. We’ve been in some crazy games. We just stay the course and figure out a way to get the victory.”