Updated

Joaquin Arias drove in the game-winning run in the ninth inning as the San Francisco Giants rallied for a 2-1 win over the Philadelphia Phillies to wrap up a three-game series.

Following an amazing start from Cole Hamels, Jonathan Papelbon (2-1) came on to close the game and immediately gave up a single to Hunter Pence. Brett Pill then punched a base hit to right to put runners on the corners, and Roger Kieschnick easily tied the game with a pinch-hit single to right. Arias then drove in the winner with a single to left.

"I still think he's a really good closer," said Phillies manager Charlie Manuel about Papelbon. "He gave up four hits in a row, but none of them were really scorched. He was using all of his pitches, they were just finding holes."

It wasn't easy for the Giants, though, as Sergio Romo had trouble of his own closing the game out in the bottom of the inning.

Delmon Young reached base on an Arias error, and Cody Asche followed with a bunt back to the mound that Romo fielded, but slipped as he tried to make a throw. John Mayberry then squared to bunt, but was hit by a pitch to load the bases with no outs.

However, Romo got Laynce Nix to fly out to shallow right, and Carlos Ruiz to fly out to shallow left before Erik Kratz hit a grounder to third that saw a force out at second to end the game and give Romo his 25th save of the season.

"For both sides that was a crazy ninth inning," said San Francisco manager Bruce Bochy. "We had some great at-bats in our half, then we were able to survive out there in the ninth. It was a little too entertaining for me, to be honest."

The rally made a winner out of Matt Cain (7-6), who gave up just one run on six hits with a pair of walks and seven strikeouts in eight innings of work. Pence had three hits to help the Giants take two of three in the series.

Hamels threw one of his best games of the season as he scattered seven hits and a walk with five strikeouts over eight innings. He also drove in the only run of the game for the Phillies.

The Phillies got that run in the fifth inning as Nix singled with two outs, Ruiz followed with a single and Hamels put a pitch into left for a 1-0 lead.

Philly, though, blew scoring chances in the seventh and the eighth with runners thrown out at the plate.

Darin Ruf led off the seventh with a walk and Michael Martinez came on to pinch run. With Mayberry at the plate, Martinez stole second and Mayberry then punched a base hit to left, but Jeff Francoeur threw a strike to the plate and Martinez was nailed.

Jimmy Rollins tripled with one out in the eighth and Michael Young followed with a grounder to shortstop, but Rollins was tagged out at home to keep it a one-run game.

Game Notes

It was Papelbon's sixth blown save of the season ... Each team won three games in the season series ... Philly hosts Atlanta for three games starting on Friday ... The Giants play three in Tampa Bay beginning on Friday ... The Giants stranded 10 runners, while the Phils left eight on the bags.