The Kings took advantage of a key foul call late in the fourth quarter to force overtime and went on to snap the Heat's six-game winning streak.
Cousins made both free throws and Sacramento was awarded the ball as well. Rudy Gay hit a jumper on the following possessions to tie it with 1:07 remaining and neither side could score again.
Thomas hit a 3-pointer early in the extra period to give Sacramento a 6-point lead and his two free throws with 12 seconds left accounted for the final score.
Sacramento overcame an early 16-point deficit to win for the ninth time this season.
Cousins scored 27 points with 17 rebounds, Gay added 26 points and Thomas had 22 to go with 11 assists.
LeBron James paced Miami with 33 points, eight assists and eight rebounds.