HOUSTON -- Ryan Vogelsong had a tough time early in his start on Thursday night.
But after using six relievers a night before, San Francisco manager Bruce Bochy was forced to stick with him despite giving up four runs through three innings.
Vogelsong (12-7) bounced back, pitching three scoreless frames before Hunter Pence hit a go-ahead two-run single in the seventh inning and the Giants rallied again for an 8-4 win over the Houston Astros.
"He kept grinding and that was a gritty effort," Bochy said. "He knew that we needed some innings out of him and he kept going and ends up getting a win. That shows you how tough he is. That was a tough start the first three innings."
The Giants were down 4-0 after four innings. They cut the lead to one with a three-run fifth inning, and Pablo Sandoval singled in a run in the seventh to tie it. Pence, who hit a three-run homer on Wednesday, then caused trouble for his former team again, this time with a two RBI grounder off Fernando Rodriguez (1-9) to shallow center field that put San Francisco on top 6-4.
San Francisco came back to win the opener of the series and Thursday's win completed their sixth sweep this season.
"Great comeback -- a couple of great comebacks here," Bochy said. "They played us tough."
Joaquin Arias added a solo homer in the eighth for the NL-East-leading Giants.
Vogelsong allowed seven hits and four runs. Sergio Romo got the last out of the ninth for his eighth save.
Tyler Greene homered for the Astros, who dropped to 1-9 under interim manager Tony DeFrancesco. DeFrancesco took over on Aug. 19 after Brad Mills became the first manager in the majors to be fired this season.
"The bottom line is we had lead going into the seventh inning, and somebody is going to have to step up out in that bullpen, and they're going to have to make pitches when they have to," DeFrancesco said.
The announced attendance was just 12,835, which set a record for the smallest crowd in the history of Houston's 12-year-old ballpark for the third straight game. The struggling Astros were competing for fans on Thursday night with both the Texans, who were hosting the Vikings in a preseason game, and Rice, which took on UCLA.
Pence walked in the eighth inning and scored from first when Brandon Belt tied a career-high with his fourth hit of the night -- a double to right field -- to extend the lead to 8-4.
Belt, who is from Nacogdoches, Texas, had a large group of family at the park for the first two games of the series. Unfortunately his wife and several members of the group went home early and missed Thursday's game after becoming ill with what he thinks was food poisoning the night before.
"Too bad my family already left," Belt said, adding that he was up all night Wednesday tending to his sick wife.
Jimmy Paredes singled to center field to score Castro and put Houston up 2-0.
Houston's Matt Dominguez, who was called up from Triple-A Oklahoma City on Thursday, hit his first career triple to lead off the second inning. He scored on a sacrifice bunt by Brian Bogusevic to push the lead to 3-0.
Greene's opposite field solo shot in the third inning left Houston on top 4-0.
"I was just kind of off early with everything -- mechanically, tempo. Everything was just kind of out of whack," Vogelsong said. "It wasn't really one thing that I changed to get going, it just kind of started falling into place."
Houston starter Jordan Lyles yielded seven hits with three runs in five innings.
Gregor Blanco singled and advanced to third on a one-out single by Vogelsong in the fifth inning. Angel Pagan cut Houston's lead to 4-1 with his run-scoring double before an RBI single by Marco Scutaro.
The Giants got within 4-3 when Pagan scored on a sacrifice fly.
Lyles got into trouble in the second inning when three consecutive singles left the bases loaded with no outs. He wriggled out of that jam by retiring the next three batters to end the inning. The last out of the inning was a nifty one, as Lyles grabbed a comebacker from Vogelsong.
Astros' OF Justin Maxwell entered the game as a defensive replacement in the seventh inning. It was the first time he's played since Aug. 21 because of a bruised right index finger. ... Houston left-hander Dallas Keuchel was optioned to Oklahoma City to make room on the roster for Dominguez. ... Houston OF Ben Francisco, who was scratched from Wednesday's lineup with discomfort in his right wrist, also sat out Thursday. ... The Astros open a series with Cincinnati on Friday and the Giants travel to face the Cubs.