Buster Posey added a solo homer in the sixth as San Francisco earned its third consecutive win. Posey, who won the NL MVP award in 2012, went 1 for 3 and is batting .103 (4 for 39) over his last 13 games.
Indians right-hander Zach McAllister was in complete control before he got into trouble in the fifth. He needed just seven pitches to get through the third and seven more to retire the side in the fourth.
McAllister (3-1) retired 12 in a row before Michael Morse led off the fifth with a single to center. Morse advanced to third on Brandon Crawford's one-out single and scored on Gregor Blanco's base hit.
Angel Pagan had a sacrifice fly before Pence's two-out hit gave the Giants a 4-3 lead.
McAllister left after the inning. He allowed five hits, struck out six and walked one after winning his previous three starts.