Lance Berkman went 2-for-4 with two RBI while rookie Jason Castro hit his first career homer and scored twice for the Astros, who won the final two games of the series after losing their previous five.
Wandy Rodriguez (4-10) was charged with just two unearned runs and four hits with a walk and three strikeouts over six innings.
Pat Burrell hit a two-run home run while Aaron Rowand went 3-for-3 with two runs scored for the Giants, who have lost four of their last six. Matt Cain (6-6) was handed the loss as he was tagged for seven runs on nine hits in just 2 2/3 innings.
Houston struck early and often as the team plated seven runs over the first three innings.
In the first with two men on, Pence clubbed a pitch over the wall in left- center and Castro led off the second with a homer to right.
Houston later loaded the bases in the second and a double from Berkman chased home two runners. Michael Bourn added an RBI double in the third for a 7-0 lead.
Burrell's two-run home run in the fourth got the Giants on the board.
The Giants put their first two men on base in the fifth, but Edgar Renteria hit into a double play and Freddy Sanchez fouled out to end the frame.
San Francisco again put their first two batters on in the sixth, but Burrell struck out and Buster Posey grounded into a double play.
The Giants cut into the deficit in the seventh. Bengie Molina reached base on a Geoff Blum error and Rowand followed with a single. Tim Byrdak took over on the mound for Chris Sampson and got the next two batters out, but consecutive RBI singles from Andres Torres and Aubrey Huff made it a 7-4 game.
Houston loaded the bases with one out in the seventh, but Bourn flied out and Jeff Keppinger struck out.
Matt Lindstrom gave up an RBI single to Renteria with one out in the ninth to make it a two-run game andTravis Ishikawa followed with a pinch-hit single to bring the go-ahead run to the plate. But Lindstrom settled down to get the next two batters and pick up his 17th save of the season.
Before the game, the Astros placed pitcher Felipe Paulino on the 15-day disabled list with shoulder tendinitis. To fill the roster spot, the team purchased the contract of pitcher Josh Banks from Triple-A Round Rock and announced he will start Saturday against Texas...Houston plays at Texas for three games starting Friday...San Francisco returns home to face Boston for a three-game set beginning Friday...Rodriguez had lost his previous three starts...San Francisco has won seven of the nine games against Houston this season...Cain has lost his last two starts.