PHILADELPHIA -- One closer faltered and the other seemed destined to do so.
After the San Francisco Giants scored twice against Philadelphia closer Jonathan Papelbon in the top of the ninth to go ahead, the Phillies loaded the bases with none out against Sergio Romo in the bottom of the inning.
But Romo somehow escaped, preserving a 2-1 San Francisco victory on Thursday night.
"He did a tremendous job," winning pitcher Matt Cain said, "of not freaking out and panicking."
Joaquin Arias singled in the go-ahead run against Papelbon in the top of the ninth.
But pinch-hitter Delmon Young reached on Arias' error at third base to start the bottom half of the inning. Phillies rookie Cody Asche bunted back to Romo, but he slipped as he was about to make a throw to first base. Asche was credited with a single, his first major league hit. Romo then hit John Mayberry Jr. with a pitch as he squared to bunt, loading the bases.
It was, Giants manager Bruce Bochy said, "as ugly a rally as I've seen."
"My mindset after that (hit batter) is, minimize the damage," Romo said. "If I were to give up the lead, leave it at that. Don't lose the game."
Romo, who had in fact lost his two previous outings, was heartened when Laynce Nix flied out to short right.
"I'm thinking I was a pitch away," Romo said. "From there on out, it was make pitches and keep the ball down in the zone."
Carlos Ruiz flied to short left and Romo retired pinch-hitter Erik Kratz on a fielder's choice bouncer to pick up his 25th save in 29 opportunities.
Cole Hamels blanked the Giants for eight innings and Papelbon (2-1), entrusted with a 1-0 lead, was seeking his 21st save. Instead he blew his sixth save in his last 13 opportunities after converting his first 13 this season.
Hunter Pence opened the Giants' ninth with an infield single. Brett Pill singled him to third and pinch-hitter Roger Kieschnick grounded a single through the right side to tie it. Arias then punched a go-ahead single through the left side.
"Tough pill to swallow," Papelbon said, "especially when it seemed like all those balls had eyes on them. ... Obviously, I want to go out and preserve the win for these starters. That's what I take pride in. Some nights you go back to the dugout and kind of scratch your head like, 'What just happened?'"
Cain (7-6) pitched eight innings, allowing six hits and one run. He struck out seven and walked two.
Hamels allowed seven hits, struck out five and walked one. He also singled home the Phillies' run in the fifth.
Cain retired the first 11 hitters he faced before Chase Utley singled with two outs in the fourth. One inning later, Hamels blooped his single to left -- the Phillies' third straight two-out hit -- to give Philadelphia a 1-0 lead.
NOTES: Giants LF Jeff Franceour erased pinch-runner Michael Martinez at the plate after Mayberry's seventh-inning single. Arias, who started at shortstop, gunned down Jimmy Rollins at home in the eighth -- the latter after the Giants brought the infield in following Rollins' one-out triple. ... A pregame drizzle prevented either team from taking batting practice on the field. ... Phillies OF Domonic Brown and LHP Cliff Lee both appear close to returning. Lee, who missed his start last Saturday with a stiff neck, threw a bullpen session on Thursday and pronounced himself fit to reporters. He is expected to start Sunday against Atlanta. Brown, out since July 23 with concussion-like symptoms, told reporters that he feels "great" and will likely go on a rehab assignment this weekend with the expectation that he will return next Tuesday against the Chicago Cubs. ... The Giants, 8-17 in July, had their lowest winning percentage (.320) in a calendar month since going 8-19 (.296) in July 1994. ... The Phillies selected the contract of RHP Ethan Martin from Triple-A Lehigh Valley. He will make his major league debut when he starts Friday against Atlanta. A corresponding roster move will be made before that game. ... Former Phillies closer Brad Lidge officially announced his retirement as a member of the team at a news conference Thursday afternoon.