Hamels took a shutout into the ninth inning before Pablo Sandoval's two-out home run. He struck out five and faced five batters more than the minimum while dominating the defending World Series champs.
All but three of the 27 outs recorded by the All-Star left-hander were made by the infield. Philadelphia also backed Hamels (13-6) with two double plays in a game that took 2 hours, 14 minutes.
The game was far less testy than Friday night's 9-2 Phillies win, which included the ejection of three players following a bench-clearing brawl in the sixth inning.
Matt Cain allowed only three hits over eight innings but took the loss, his second straight. San Francisco has dropped eight of nine since taking two of three games from the Phillies at Citizens Bank Park.Hamels had only one victory in his previous four starts and lost to San Francisco 2-1 on July 27 despite pitching into the eighth inning and allowing only two runs and six hits.
He was even stronger in the rematch and got better results while outdueling Cain.
Hamels, who hadn't won since July 22, faced the minimum through three innings, then gave up back-to-back singles in the fourth. He quickly worked out of the jam, striking out Carlos Beltran on three pitches before Sandoval grounded into a 4-6-3 double play in the first pitch.
San Francisco didn't get another runner until the seventh, and had two on with two outs in the eighth but failed to score each time.
The Giants, blanked by Cliff Lee in the series opener, are hitless in 17 at-bats with runners in scoring position in the three games against the Phillies this weekend. Over its last 16 games, San Francisco is batting .157 (16 for 102) with runners in scoring position.
Before the game, Giants manager Bruce Bochy said he expects to hear soon from Major League Baseball about penalties for Friday's bench-clearing brawl.
San Francisco reliever Ramon Ramirez and catcher Eli Whiteside were both ejected along with Philadelphia center fielder Shane Victorino.
Victorino was booed during pregame introductions and every at-bat by the sellout crowd at AT&T Park, but there were no other lingering effects from the fight.
Cain (9-8) nearly matched Hamels, retiring 20 of the final 22 batters he faced after giving up both Philadelphia runs in the first. The right-hander struck out eight and walked two.
Jimmy Rollins doubled high off the wall in right-center leading off the game, and after Chase Utley drew a one-out walk and Ryan Howard struck out, Hunter Pence hit a bloop single to right to drive in Rollins.
Utley tried to take third on the play and appeared to be out following a strong throw by Nate Schierholtz, but Sandoval bobbled the ball, allowing Utley to reach safely. Three pitches later he scored on a passed ball to make it 2-0.
Notes: Friday's winning pitcher, Vance Worley, is the first Phillies rookie to win six games over a seven-game stretch since Bob Walk in 1980. ... Phillies 3B Placido Polanco left the game with soreness in his left hip. ... Philadelphia has an NL-best 28-11 record during day games. ... Giants reliever Sergio Romo has retired 30 consecutive batters, the longest streak in the majors. ... Philadelphia homered in its previous eight games, the team's longest streak since 2009. ... RHP Tim Lincecum (9-9) has six straight quality starts against the Phillies and will try to stop the Giants' slide when he opposes RHP Roy Oswalt (4-6) in Sunday's series finale. Oswalt will be making his first start since going on the disabled list with lower back inflammation on June 24.