HOUSTON (AP) -- When Barry Zito had already surrendered seven hits with one out in the third inning, San Francisco Giants manager Bruce Bochy knew he needed to get him out of the game.
His early exit forced Bochy to use six relievers to piece together the game and hold on for the 6-4 win over the Houston Astros on Wednesday night.
''The bullpen really picked us up tonight,'' Bochy said. ''Z was a little off and we had to go get him early. They just did a terrific job of picking us up.''
Hunter Pence hit a three-run homer and Joaquin Arias drove in two with a triple to help in the win.
Pence has been a nightmare for the Astros since they traded him away in July 2011, hitting four homers in just seven games against his former team with the Phillies and Giants.
The Giants had a 1-0 lead before Pence's 19th homer pushed the lead to 4-0 and elicited the loudest cheers of the night from the sparse crowd.
''It's a nice vibe to play here,'' said Pence, who spent the first 4 1/2 years of his career in Houston. ''The fans have always been really good to me, and they're still pretty supportive for the most part. It's humbling to have that support.''
The announced attendance was just 13,207, the smallest crowd in the history of Houston's 12-year-old ballpark. The previous record-low came a night before as the Astros struggle to get fans out to see this team that has the worst record in the majors.
Houston cut the lead to 1 before Arias' triple in the sixth inning, which came after an error by the Astros, pushed the advantage to 6-3.
Angel Pagan hit a leadoff double, advanced to third on a sacrifice bunt and scored on a single by Pablo Sandoval to give San Francisco a 1-0 lead. Buster Posey walked before Pence's shot to left-center of Dallas Keuchel (1-7) pushed the lead to 4-0.
Chris Snyder doubled in the second inning and scored on a two-out single by Brandon Barnes to cut the lead to 4-1. Snyder slid in behind Posey to beat the throw home.
Jose Altuve singled and stole second base in the third inning before scoring after consecutive singles by Tyler Greene and Brett Wallace. A sacrifice fly by Jimmy Paredes sent Greene home and got Houston within 4-3.
A single by Fernando Martinez chased San Francisco starter Barry Zito, who was replaced by George Kontos (1-0). Kontos struck out four in 2 2-3 scoreless innings for his first major league win.
''It was awesome - everything I thought it would be,'' Kontos said. ''When I first came into the big leagues, I thought my first win would be as a starter, but it felt just as good as a reliever.''
Zito yielded seven hits and three runs in a season-low 2 1-3 innings. He understood why Bochy lifted him when he did.
''These are must-win ballgames, and I didn't have it tonight,'' Zito said. ''My command was below average for sure. My timing was off and that ended up making my command off. I was very upset with myself.''
Javier Lopez got the last two outs for his fifth save.
The loss is Houston's fourth straight and its 11th in the last 12 games. The Giants improved to 16-5 on the road since the All-Star break, which is the best record in the majors.
Keuchel had retired 14 in a row after Pence's homer before Marco Scutaro started the sixth inning with a double which bounced off the wall in left field.
Sandoval drew a walk after that to end Keuchel's night. He allowed four hits and five runs in 5-plus innings.
He was replaced by Mickey Storey, who got Posey to ground into a double play. Pence reached on an error by third baseman Scott Moore before the triple by Arias.
The fly ball by Arias sailed just out of reach of leaping left fielder Martinez and rolled into the corner to score Sandoval and Pence and push the lead to 6-3.
New Astros' manager Tony DeFrancesco was disappointed that Houston let another close one slip away.
''They're playing hard and giving us a chance,'' DeFrancesco said. ''There's a lot of good things happening, and we're playing some good teams that are trying to get to the playoffs.''
San Francisco's Guillermo Mota, who was activated from the restricted list on Tuesday after serving a 100-game suspension for his second positive drug test, made his first appearance since May 5 in the sixth inning. Mota, who tested positive for Clenbuterol, which he says was in children's cough syrup, allowed a hit and a walk in 2-3 innings.
He was replaced by Jose Mijares, who promptly gave up an RBI single to Scott Moore to make it 6-4. He walked Altuve to load the bases before striking out pinch-hitter Brian Bogusevic to escape the jam.
Moore went 2 for 2 after entering the game in the sixth inning to break an 0 for 21 skid.
NOTES: Former Astros star Craig Biggio addressed the team before Wednesday's game at the request of DeFrancesco. DeFrancesco said he wants to teach the young team how the Astros were during their years of success when Biggio played. Biggio wouldn't say what he told the team, but said he's willing to do whatever he can to help this team get back on track. ... Houston LF Ben Francisco was scratched before the game. DeFrancesco said after the game that he strained ligaments in wrist in batting practice and went for evaluation. ... The Giants placed reliever Clay Hensley on the 15-day disabled list with a right groin strain and activated reliever Jeremy Affeldt from the paternity list. Affeldt pitched a scoreless seventh inning.