Hamels (5-5) stymied the first-place Giants with eight innings of one-run ball, striking out 10 to help the Phillies avoid a four-game sweep. Jonathan Papelbon threw a 1-2-3 ninth inning to notch his 24th save.
The Phillies pushed across a run in the bottom of the first inning on an RBI single by Marlon Byrd. The Giants got to Hamels in the top of the fifth inning to knot the score on Ehire Adrianza's two-out base hit to score Gregor Blanco.
Chase Utley quickly snatched the lead back for the Phillies with an RBI single in the bottom of the fifth, making it 2-1.