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.
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-centre of Dallas Keuchel (1-7) pushed the lead to 4-0.
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.
Zito yielded seven hits and three runs in a season-low 2 1-3 innings.
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.
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.
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.
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.
NOTES: Former Astros star Craig Biggio addressed the team before Wednesday's game at the request of new manager Tony 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 with discomfort in his right wrist. He was replaced in the lineup by Martinez. ... 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.