Donatas Motiejunas scored 23 points and the Houston Rockets used a big run late in the fourth quarter to break open a close game and get a 107-94 win over the Orlando Magic on Tuesday night.

On a night when James Harden struggled offensively, Houston used a balanced scoring attack with six players in double figures to get the victory.

A driving layup by Victor Oladipo got the Magic within 2 points with about five minutes left before the Rockets used a 13-0 run, powered by three 3-pointers, to make it 107-92 with less than a minute remaining.

Orlando's only points in the last 4:40 came on a basket by Ben Gordon with about 40 seconds left.

Harden, who is second in the NBA in scoring, went 4 for 14, but made eight free throws to finish with 17 points.

Oladipo's 29 points led the Magic, who have dropped four in a row.

Along with Motiejunas and Harden, Trevor Ariza (17), Josh Smith (17), Corey Brewer (13) and Patrick Beverley (12) also scored more than 10 points.

Orlando was up by 3 early in the fourth quarter when Houston went on a 9-2 run, capped by a one-handed slam by Smith, to take an 86-82 lead with about nine minutes remaining.

Houston led by a basket with about eight minutes left in the third quarter when Oladipo swiped the ball from Harden and finished on the other end with a two-handed dunk to tie it up.

The teams exchanged the lead several times in the third quarter after that but neither team led by more than three points until the Magic made seven straight points, with by a 3-pointer by Channing Frye, to take a 78-71 lead.

But Smith made two 3-pointers in the last 27 seconds of the third quarter, including one at the buzzer with Frye in his face, to cut the lead to 78-77 entering the fourth quarter.

The Rockets were up by 1 midway through the second quarter when they went on an 8-4 run, with all of their points by Motiejunas, to push the lead to 46-41 about three minutes before halftime.

But Gordon made five quick points to start a 7-0 run by the Magic that gave them a 48-46 lead.

The game was tied soon after that when Gordon was called for goaltending on a shot by Harden that he was fouled on. Harden was 0 for 6 before that shot and made the free throw to put Houston back on top.

The Rockets led 51-50 at halftime.

TIP-INS

Magic: The Magic won the first meeting this season 120-113. ... F Tobias Harris sprained his left ankle in the second quarter and didn't return.

Rockets: Coach Kevin McHale switched up the lineup on Tuesday night, starting Joey Dorsey in place of Terrence Jones, who had started the last 11 games. ... Brewer had a season-high 12 rebounds.

UP NEXT

Magic: visit Dallas on Wednesday.

Rockets: host Nuggets on Thursday.

© 2015 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed. Learn more about our Privacy Policy and Terms of Use.