Hayes had 14 rebounds, 13 points and 11 assists for the Rockets, who remained two games behind Memphis for the final playoff spot in the Western Conference. With the crowd cheering him on, Hayes missed several chances to get the triple before his jumper with 6:26 left clinched it.
Dorell Wright led the Warriors with 34 points, David Lee had 19 and Stephen Curry finished with 16.
Houston hit 12 of 26 attempts from 3-point range, led by Martin's 4-for-7 effort.
The Rockets took a 66-57 halftime lead and stretched it to 92-76 with 3:16 to go in the third quarter.
Golden State led only once at 16-15 in the first quarter and took advantage of a 3:31 scoreless streak by Houston to tie it at 57 with 2:20 to go in the second. Two free throws by Monta Ellis, a three-point play by Lou Amundson and a basket by Al Thornton rallied the Warriors to the tie.
Lee hit a 3-pointer to put Houston back ahead, and Martin followed with a three-point play and a 3-pointer to keep the Rockets in the lead at intermission.
Scola ignited the Rockets in the first quarter, scoring eight of Houston's first 11 points. He had 14 in the opening quarter and the Rockets took a 36-33 lead despite the fast-breaking success of Wright, who got six early points on fast breaks and had 10 after one quarter.
Notes: Martin averaged 27.7 points in his previous three games against Golden State. ... Houston closed out its longest home stand of the season at 5-1. ... The Warriors have lost six in a row in Houston and 12 of their last 13 against the Rockets. ... Budinger missed the game with a sprained left ankle. ... Curry has made 126 of his last 133 free throws. He did not shoot a free throw Wednesday night.