James Harden had 38 points and made 19 of 19 foul shots for the Rockets, who ended a six-game winning streak.
Houston scored six straight points, including three free throws from Harden, to make it 108-103 with about 7 1/2 minutes left.
Delon Wright made a free throw for the Raptors soon after that, and OG Anunoby connected for Toronto's first field goal in more than three minutes on a 3-pointer with 6:25 remaining. After Wright's layup, Kyle Lowry stole the ball from Harden, and DeRozan finished on the other end with a dunk to make it 116-103.
Harden got Houston going again with a four-point play. The free throw was his 19th, setting a franchise record for most foul shots without a miss in a game.
DeRozan and Serge Ibaka had back-to-back dunks after Harden's big play to make it 120-107 with about three minutes left and send many of the home fans toward the exits.
Harden had 11 assists and six rebounds. He has scored at least 20 points and had seven or more assists in every game this season.
Toronto's C.J. Miles opened the fourth quarter with a 3-pointer to make it 106-94.
The Raptors scored the first five points of the second half to make it 81-64 and pushed their lead to 19 points midway through the third when Lowry made a 3-pointer.
Toronto led by 21 before Houston made five straight points, capped by a 3-point play by Tarik Black. That was the start of a nice run for the Rockets, and they used a 9-3 spurt after that to cut the lead to 97-87. Harden made four points in that span, and Eric Gordon capped it with a layup.
Houston led by eight points during the first half, but the Raptors used a 45-point second quarter to take a 76-64 edge into halftime.
Raptors: Norman Powell sat out after leaving Sunday's game at Boston with a hip pointer. ... Lowry, a former Rocket, added 19 points and 10 assists. ... Anunoby scored 16 points.
Rockets: Nene missed his second straight game with a sprained right foot. ... Harden received a technical after a shot in the first quarter when he complained about the lack of a foul call. ... Trevor Ariza finished with 20 points and eight rebounds. ... P.J. Tucker got two technical fouls and was ejected in the third quarter.
Raptors: Visit New Orleans on Wednesday night.
Rockets: Visit Phoenix on Thursday night.
More AP basketball: https://apnews.com/tag/NBAbasketball