Blum led off the fifth inning with a home run, the first earned run given up by Cain in 14 innings. That cut the Giants' lead to 2-1, and Matsui put the Astros on top in the sixth inning with a two-run shot off the right-field foul pole.
Cain (12-3) also gave up Carlos Lee's run-scoring single in the eighth inning.
Mike Hampton (7-8) gave up eight hits, only one after the Giants took a 2-0 lead in the third inning. The left-hander struck out six and won for only the third time in eight starts.