The Astros dropped their fourth in a row and have suffered 90 losses this season. To avoid another 100-loss campaign, Houston will have to compile a 23-9 record the rest of the way.
San Francisco won for the ninth time in 12 games even though starter Barry Zito lasted only 2 1/3 innings.
After Zito gave up three runs on seven hits, George Kontos (1-0) came on to throw 2 2/3 perfect innings. Kotos won for the first time in 39 major league appearances. Javier Lopez needed just four pitches to retire the final two batters in the ninth for his fifth save.
Dallas Keuchel (1-7) retired 14 straight batters after giving up Pence's first-inning homer, but still suffered the loss.
Houston closed within 3-2 before Joaquin Arias gave San Francisco some breathing room with a two-run triple in the sixth.
For the second night in a row the Astros established a record-low attendance figure at Minute Maid Park. They drew 13,516 on Tuesday and 13,207 on Wednesday.
Kate Moss Playboy shoot is classic Playboy, classic Kate
Caroline Berg Eriksen: Soccer player's wife triggers debate with post-birth selfie