The Heat stretched their NBA home winning streak to 17 games, somewhat making up for a blowout defeat two weeks ago in Oklahoma city.
Dwyane Wade, returning after sitting out Tuesday with a bruised left knee added 19 points for the Heat, who also got 12 from Chris Bosh.
Kevin Durant led the Thunder with 30 points and Russell Westbrook added 18 points in a game that turned testy at times.
Thunder center Kendrick Perkins was assessed a technical foul and Westbrook a flagrant foul in two separate second quarter incidents.
Miami led by seven going into the fourth quarter, but Oklahoma City battled back courtesy of an 8-0 scoring run.
After Miami had regained the advantage, Durant had a chance to give Oklahoma City the lead again with 1:30 remaining, but missed a jump shot attempt.
Bosh then drained a jump shot to make it 96-93 for Miami.
Perkins missed two free throws with 43 seconds left — Oklahoma City’s first misses from the foul line in the contest.
After a Thunder timeout with less than 20 seconds to play, Durant was off-target with a three-pointer and Wade made two free throws to give the Heat some breathing room.
With the victory Miami improved to 39-14 and moved within two games of Chicago (42-13) for the NBA’s best record.
Oklahoma City fell to 40-14 and found themselves just one game in front of San Antonio for the best record in the West after the Spurs’ dramatic 87-86 victory over Boston.