The Miami Heat set an NBA record by going 40-for-40 at the free throw line and used a 6-0 run to end the game to beat the Oklahoma City Thunder 112-111 on Tuesday night at FTX Arena in Miami, Florida.

The Thunder outshot Miami 48 percent to 39 percent from the field, but Miami made 10 three-pointers to OKC’s nine, and attempted 19 more free throws.

Jimmy Butler made a layup and was fouled with 12 seconds left, with the free throw giving Miami a one-point lead.

Butler finished with 35 points to lead all scorers and was 23-for-23 at the free throw line.

Shai Gilgeous-Alexander missed a 3-pointer in the final seconds that would have given the Thunder the lead.

SGA led the Thunder with 26 points.

There were six ties and 10 lead changes in the game, and neither team led by more than 11 points, with the Heat taking that advantage late in the first half.

Josh Giddey had a triple-double for OKC, with 18 points, 15 rebounds, and 10 assists.

Three other OKC players scored in double figures, with Kenrich Williams scoring 13 points off the bench.

Jalen Williams added 12 points and Luguentz Dort 11.

The game was the first of a four-game road trip for the Thunder, who dropped to 18-23 overall.

OKC visits Philadelphia on Thursday for a 6:00 pm tipoff.