Four consecutive singles off Phillies closer Jonathan Papelbon, including hits by newcomers Brett Pill and Roger Kieschnick, generated San Francisco's scoring.
The Giants remain far below .500 at 48-59, and trail the first-place Dodgers by 9 1/2 games in the National League West. All that the reigning World Series champions hope to do is deliver more efforts such as this to avoid a wasted season and generate hope for the next one.
"You know the numbers are kind of stacked against us," said right-hander Matt Cain (7-6), who was bound for a complete-game defeat before the Giants rallied. "We just want to go the rest of the season playing well and having a good time. It's no fun when things aren't going well and you're losing. We've done enough of that recently."
Another setback loomed as the Giants trailed, 1-0, and Papelbon replaced Cole Hamels, who blanked them on seven hits through eight innings.
Hunter Pence opened the ninth inning by beating out a grounder to shortstop for his third hit. Pill, starting his third straight game since being recalled from Triple-A Fresno, followed by guiding an 0-2 pitch into right field. Pence made a daring dash for third base and succeeded.
Due up to face the right-handed Papelbon was righty-swinging Jeff Francoeur, batting .167. Giants manager Bruce Bochy opted to use Kieschnick, a left-handed batter whose Major League career was one game old, to bat for Francoeur, a nine-year veteran.
"After the game 'Keesh' had yesterday (2-for-5, two RBIs), he had great composure out there," Bochy said. "He wasn't in awe of anything."
Kieschnick grounded Papelbon's first pitch into right field to score Pence with the tying run. Joaquin Arias singled to left on an 0-1 split-finger fastball, sending Pill home with the go-ahead tally.
In came Romo, coming off the first pair of back-to-back losses in his career. By the time he threw nine pitches, Philadelphia filled the bases. Arias, who moved from shortstop to third base, mishandled pinch-hitter Delmon Young's grounder for an error. Cody Asche's sacrifice-bunt try turned into a single when Romo fielded the ball, looked toward second base for a potential force play and slipped as he wheeled for a throw to first. Then Romo hit John Mayberry Jr. with a pitch.
"The mindset after that is to minimize the damage," Romo said.
Laynce Nix popped out to shallow right field, changing Romo's mindset from surviving to winning.
"I was thinking I was one pitch away," he said, confident of coaxing a double-play grounder. Instead, Carlos Ruiz flew out to left field and pinch-hitter Erik Kratz grounded into a force play, sealing Romo's 25th save in 29 chances.
The Giants warmed up for the ninth in the previous two innings. In the seventh, Francoeur, playing left field, denied the Phillies a run by charging Mayberry's single and unleashing a one-hop throw to retire pinch-runner Michael Martinez, who was trying to score from second base.
"Even when you're not hitting, you can do other stuff," Francoeur said.
Jimmy Rollins tripled in the eighth with one out, but with the infield playing in, was thrown out trying to score as Arias deftly handled Michael Young's grounder and threw home.
Those plays supplemented Cain's second impressive performance in a row. He yielded six hits and struck out seven in eight innings, nicely following his one-run, six-hit effort over seven innings last Friday against the Cubs.
"No one gave up," Romo said. "Everyone kept pushing."