San Francisco then countered in the 10th while facing Anthony Bastardo (1-1).
Posey, pinch-hitting for Brandon Belt, led off with a single, went to second on a Joaquin Arias sacrifice bunt and to third on a wild pitch.
After Brandon Crawford walked and Guillermo Quiroz struck out, Torres delivered a solid hit to right field, driving in the game-winner.
Javier Lopez (1-0) earned the decision with a scoreless top of the 10th for the Giants, who salvaged one win in their three-game series.
Hunter Pence socked a solo homer for San Francisco.
Kevin Frandsen went deep for Philadelphia.