HOUSTON — James Harden matched a franchise record for free throws without a miss and the Houston Rockets held on for a 107-106 victory over the Boston Celtics on Monday night at Toyota Center.

Harden finished with a game-high 37 points on 8-of-14 shooting, adding 18 free throws to his scoring line. He added seven rebounds and eight assists and nailed a 3-pointer with 54.8 seconds left that provided Houston (14-7) with the winning margin.

The Celtics (12-9) had two shots at the basket in the waning moments, including a driving layup from center Al Horford that rolled off the rim just before the final buzzer.

Horford led Boston with 21 points and nine assists. Isaiah Thomas added 20 points and Avery Bradley had 16 points and 10 rebounds.

Bradley hit a jumper with his foot on the line to pull Boston within one point with 46.9 seconds left.

Eric Gordon scored 19 points off the bench for Houston and forward Trevor Ariza chipped in 15 points and eight rebounds.

Houston trailed by as many as eight points in the fourth quarter before Harden keyed the comeback with four free throws before Patrick Beverley delivered the defensive play of the game. Beverley stripped Celtics forward Jonas Jerebko and coasted in for an uncontested layup with 3:44 left that tied the score at 100.

On the ensuing possession, Montrezl Harrell finished a nifty pass from Ariza with a dunk that provided the Rockets their first lead since the third quarter.

The Celtics’ ability to counter the Rockets’ surge out of the intermission proved decisive. After a Harden finger roll and two Clint Capela baskets at the rim, Houston extended the lead to a game-high 12 points at 65-53.

Boston followed by hitting 5 of 7 baskets, including 3s from Jae Crowder, Jerebko and Horford as part of a 15-2 run.

The Rockets could not match the Celtics’ sudden scoring burst and the poor perimeter shooting that plagued Houston in the first half continued in the third quarter. The Rockets were 1 of 10 from behind the arc in the quarter as Boston extended to a 79-72 lead on two Thomas free throws with 2:44 remaining in the third quarter.

With some help from Gordon and Ariza, Harden essentially carried the Rockets to a 10-point lead at the break on the strength of his remarkable ability to draw fouls.

While Gordon and Ariza combined for 19 points on 4-of-10 shooting from deep in the first half, Harden made 11 trips to the free-throw line and converted each time. He poured in 21 points at the break and added five rebounds and six assists.