McGrady, 1-for-16 shooting in his previous two games, made 11 of 18 shots, going 9-of-14 in the second half as the Rockets used a tough defense to dominate the Suns and spoil O'Neal's big night.
The Suns center scored 18 points to move past John Havlicek into 10th on the NBA career scoring list. O'Neal also grabbed 13 rebounds.
What was mostly a shoving match broke out just after McGrady's 3-pointer put Houston ahead 74-55 with 27 seconds left in the third quarter. Houston's Rafer Alston, apparently upset after getting a shoulder from Matt Barnes, shoved the Phoenix player at midcourt.
Steve Nash rushed into middle of things and was pushed to the court by McGrady, who in turn was shoved down by O'Neal.
After coaches and officials separated the players, the referees huddled and decided to eject Alston and Barnes with double technicals. McGrady, Nash and O'Neal all drew technical fouls, an outcome that was greeted by a chorus of boos from the crowd. The net result was a technical free throw for Houston, which Yao Ming missed.
Yao added 17 points and 15 rebounds for the Rockets, who led by 19 entering the fourth quarter.
Aaron Brooks scored 19 and Alston 15 for Houston. The Suns' Leandro Barbosa scored 18 on 5-for-14 shooting.
Phoenix, the best shooting team in the NBA going into the game (51.5 percent), shot just 38 percent (32-for-85).
Houston outscored the Suns 15-8 to start the second quarter, taking a 38-30 lead on consecutive jumpers by Brooks. The Suns missed three shots and had two turnovers in their last five possessions of the half to trail 44-37 at the break on Ron Artest's 18-footer at the buzzer.
Artest missed his first seven shots before his buzzer-beater. He finished 1-for-11. The Suns' Amare Stoudemire scored just two points on 1-for-4 shooting and didn't go to the foul line in the first half. He finished with 11 points, going 5-of-13 from the floor.
Notes: With 26,402 points, O'Neal needs 267 to pass Dominique Wilkins into ninth place. ... The Portland Trail Blazers will retire Phoenix coach Terry Porter's No. 30 on Dec. 13. Three nights later, the Blazers will retire No. 30 again, this time for Bob Gross. Gross' ceremony comes the night the Suns play Portland. ... Nash's half-court basket at the end of the third was ruled no good after a review. ... The Rockets were on their fourth stop of a five-game road trip that ends Friday in San Antonio.