PHILADELPHIA -- Cole Hamels played stopper Thursday afternoon, pitching the Philadelphia Phillies to a 2-1 win over the San Francisco Giants at Citizens Bank Park.

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. The left-hander has a 1.75 ERA since June 1.

Closer Jonathan Papelbon threw a 1-2-3 ninth inning to notch his 24th save.

The last-place Phillies (44-58) have won just two of their last nine games -- both 2-1 victories in which Hamels was the winning pitcher. The Giants (57-45) went 5-2 on their seven-game road trip to open the second half with a pivotal series with the Los Angeles Dodgers ahead.

Philadelphia took advantage of two San Francisco blunders to score a pair of unearned runs, and that was all Hamels needed.

Giants starter Tim Hudson (8-7) threw six innings, and both Phillies runs were unearned.

The Phillies pushed across a run in the bottom of the first inning run on an RBI single by right fielder Marlon Byrd. With one out, shortstop Jimmy Rollins flared a double down the left field line and moved to third on a passed ball. Second baseman Chase Utley followed with a walk before Byrd singled to left, putting Philadelphia ahead 1-0.

The Giants got to Hamels in the top of the fifth inning to knot the score, as second baseman Ehire Adrianza delivered a two-out base hit up the middle to score center fielder Gregor Blanco, who singled to lead off the inning.

Utley quickly snatched the lead back with an RBI single of his own in the bottom half of the fifth, regaining Philadelphia a 2-1 advantage. Center fielder Ben Revere scored after reaching second base on an error by left fielder Michael Morse, who dropped a shallow fly ball to start the inning.

The opening frame could have been worse for Hudson. With runners on first and second and one out after the first unearned run, left fielder Grady Sizemore hit a line drive up the middle, but shortstop Joaquin Arias -- placed perfectly behind second base -- snared it and stepped on second for an unassisted, inning-ending double play.

The Giants threatened in the top of the fourth against Hamels. San Francisco loaded the bases with two outs after Utley airmailed a throw to first on a potential inning-ending double-play ground ball. Hamels, however, saw his way out of the jam by getting Arias to ground out to shortstop.

NOTES: Phillies 1B Ryan Howard was out of the starting lineup for the second consecutive game. Manager Ryne Sandberg wants 1B Darin Ruf, who was recalled from Triple-A Lehigh Valley on Tuesday, to get some work at the position, especially given the struggles of Howard this season. ... The Giants head home to face division rival Los Angeles Dodgers for three games. The Dodgers are in second place in the NL West behind the Giants. ... The Phillies welcome the Arizona Diamondbacks for three games at Citizens Bank Park this weekend before starting a seven-game road trip.