John Mayberry Jr. hit two solo homers for the last-place Phillies, and Nate Schierholtz hit a pair of solo shots for the NL West-leading Giants.
The Phillies snapped a seven-game home losing streak and avoided their first sweep against the Giants since 2004.
Brad Penny (0-1) walked Carlos Ruiz with one out in the 12th. Laynce Nix followed with a single to right to move Ruiz to third. Rollins then lined the first pitch to right to end it.
The five-time defending NL East champions are 10½ games behind Atlanta in the wild-card standings.
Kyle Kendrick (4-8) tossed 2 1-3 innings to earn the win and extended his career-best scoreless streak to 18 2-3 innings.
Phillies starter Joe Blanton gave up three runs and seven hits in eight innings, increasing his trade value with another strong second-half start. Since 2008, Blanton has the best record in the majors after the All-Star break at 17-5.
The right-hander will be a free agent after the season, so the Phillies might move him before the July 31 non-waiver trade deadline unless they start to make a run.
San Francisco's Barry Zito allowed three runs and five hits, striking out seven in seven innings. Zito is having his best season for the Giants since signing a $126 million, seven-year contract in December 2006.
After Mayberry gave the Phillies their first lead, 3-2, on his second homer in the seventh, Schierholtz answered with his second in the eighth. He hit a high drive to right to tie it at 3.
Blanton escaped further trouble in the inning when right fielder Hunter Pence saved two runs by making a running basket catch on Buster Posey's deep fly to right.
Mayberry drove a 3-2 pitch into the seats in left to tie it at 2 in the fourth. He hadn't driven in a run in his previous 39 at-bats, going back to June 24.
Pablo Sandoval's RBI double to left-center gave the Giants a 2-1 lead in the fourth.
Schierholtz ripped a 2-0 pitch way out to right for his first career leadoff homer to give the Giants a 1-0 lead.
Chase Utley's RBI triple in the bottom half tied it at 1. Zito escaped a first-and-third, one-out jam by getting Pence to ground into his 13th double play.
Zito stranded runners on second and third in the third by striking out Ryan Howard on a 74 mph curveball.
NOTES: Blanton has allowed 22 homers, second-most in the majors. ... Zito allowed his 12th earned run in the first inning in 19 starts. ... Melky Cabrera extended his hitting streak to nine games with a first-inning double. ... Schierholtz has five homers this season, including two multihomer games. ... Nix came off the disabled list after missing more than two months with a left calf strain. OF Jason Pridie was designated for assignment. He went 3 for 10 with a homer in a brief stay. ... Mayberry has hit all eight of his homers since May 11. ... The Phillies had their 267th consecutive sellout, including postseason games. ... Roy Halladay (4-5, 3.96 ERA) makes his second start since returning from the disabled list when the Phillies open a three-game series against Milwaukee on Monday night. ... Ryan Vogelsong (7-4, 3.21) pitches for the Giants in the opener of a three-game series against San Diego on Monday.