Madison Bumgarner worked into the eighth inning and hit his first career homer as the host Giants won the opener of the three-game series.
Bumgarner (8-4) improved to 13-2 in his last 16 starts at AT&T Park after giving up two runs (one earned) on six hits with no walks and a season-high 12 strikeouts over 7 2/3 innings.
The Giants snapped their 16-game homerless drought at home when Bumgarner led off the third inning with a solo shot off Bud Norris (5-4).
Brandon Belt added his first home run of the season in the eighth inning, a two-run shot off Wesley Wright.
Norris ran into trouble in the fourth when he walked the bases loaded and gave up a two-run double to Brandon Crawford before leaving the game with a left knee sprain.
San Francisco led 4-1 in the seventh on Melky Cabrera's RBI single off Brandon Lyon. Cabrera went 2-for-4 after missing three straight starts with a hamstring injury.
Brian Bixler, who singled in a run in the third inning, cut the Giants' lead in half with his RBI double in the eighth inning. Sergio Romo struck out J.D. Martinez with Bixler at second to end the inning.
Houston, which fell to 8-21 on the road, scored a run on Jason Castro's two-out double in the top of the ninth before Santiago Casilla entered the game and retired Brett Wallace for his 17th save.
NOTES: The Giants signed right-handed pitcher Chris Stratton, their first-round selection (20th overall) in the Major League Baseball draft. The Giants have come to terms with 10 of their first 20 selections from last week’s draft. ... Bumgarner's homer was the first by the Giants at home since May 14. ... After homering in three of his last four games, Astros shortstop Jed Lowrie went 0-for-4 with three strikeouts. ... San Francisco improved to 8-3 in June and remained 4 1/2 games behind first-place Los Angeles. ... Bumgarner has struck out 10 or more batters in three of his last five starts. ... Astros first baseman Carlos Lee (hamstring) is expected to begin a rehab assignment later this week.