DeMarcus Cousins made a layup with 8.5 seconds remaining in regulation to extend the game after 48 minutes, and then the real action began.
Next, Isaiah Thomas hit a go-ahead three-pointer to put the Kings up by one in the first overtime before LeBron James got to the free-throw line and made 1-of-2 to send the game into the second overtime before the Heat closed the game out.
James led all scorers with 40 points on 14-of-23 shooting for Miami (41-14). He added 16 assists and grabbed eight rebounds in the winning effort. Dwyane Wade had 39 points, seven assists and eight rebounds.
Marcus Thornton was phenomenal off the bench with 36 points for Sacramento (19-39), including eight three-pointers on 12 attempts. Cousins collected a double-double with 24 points and 15 rebounds
If nothing else, the Kings exposed the Heat's deficiencies inside as they grabbed 14 offensive rebounds. Miami overcame that issue, however, by shooting 55 percent from the field and committing just 12 turnovers in 58 minutes of action.
Miami extended its league-best winning streak to 12 games with the win.
More in the NBA: