Jonathan Papelbon (2-4) walked Melky Cabrera to start the 10th. He advanced to third on a single and scored with out on Blanco's perfect bunt down the first-base line.
Cabrera hit a tying homer off Hamels in the eighth and Buster Posey hit a two-run shot for the NL West-leading Giants, who are 7-1 since the All-Star break.
Ryan Howard hit a three-run homer and Chase Utley also went deep for the last-place Phillies, who have lost three in a row, seven straight at home.
Hamels allowed five runs and 10 hits, including three homers, in 7 2-3 innings on a career-high 128 pitches.
Cain gave up five runs and five hits, including three homers, in eight innings.
Sergio Romo (3-1) retired the two batters he faced in the ninth and Santiago Casilla finished for his 24th save.
DIAMONDBACKS 12, ASTROS 3
PHOENIX (AP) — Jason Kubel became the seventh player in Diamondbacks' history to homer three times in a game and he drove in six runs as Arizona dominated Houston for the second straight game.
Kubel hit a two-run home run in the first inning and a three-run shot in the fourth off starter Dallas Keuchel (1-2). He added a solo homer in the sixth. He struck out in his other two at-bats.
With the first three-homer game of his career, Kubel leads the NL with 70 RBIs. He has 20 home runs.
Wade Miley (11-5) gave up a run and four hits in seven innings, striking out a career-high nine while setting a franchise rookie record for victories.
The Astros, who have been outscored 25-11 in the two games with Arizona, lost their fifth straight and 18th in 20 games.
Kubel, signed as a free agent in the off-season, is one of six players to hit three home runs in a game this season. That includes Josh Hamilton, who hit four.
Keuchel, called up from Triple-A Oklahoma City for the start, allowed seven runs and seven hits and walked four in 3 1-3 innings.
BRAVES 4, NATIONALS 0, 1st game
NATIONALS 5, BRAVES 2, 2nd game.
WASHINGTON (AP) — Bryce Harper returned from an ankle injury to single and score as a pinch-hitter, and Roger Bernadina had a tiebreaking hit in the seventh inning as Washington earned a split of the day-night doubleheader.
Harper injured his ankle in the opener and was lifted after the second inning. The Braves won the first game 4-0 behind Ben Sheets' strong pitching performance.
Bernadina, who entered as a defensive replacement after Harper fouled a bunt off his left ankle in the first inning of the first game, had five hits on the day including the seventh-inning, go-ahead RBI single in the nightcap.
Between games Nationals manager Davey Johnson said the MRI on Harper showed no break. He kept the 19-year-old out of the starting lineup for Game 2.
Harper entered as a pinch-hitter in the eighth with the Nationals leading 3-2. He singled, stole second and scored on Danny Espinosa's single.
John Lannan (1-0) pitched seven innings for the win that snapped Washington's three-game losing streak.
Tyler Clippard pitched the ninth for his 16th save.
Cristhian Martinez (4-2) allowed a run in 1 1-3 innings of relief.
In the opener, Sheets pitched six shutout innings and Brian McCann and Chipper Jones homered for the Nationals.
Sheets (2-0) extended his scoreless innings streak to 12 in his return after missing last season because of Tommy John surgery on his right elbow.
McCann hit a solo homer in the second inning, his 16th, and Jones, entering as a pinch-hitter in the ninth with a runner on, hit his ninth.
Sheets allowed five hits with six strikeouts and three walks.
Nationals starter Edwin Jackson (5-6) struck out nine while allowing five hits and two walks over seven innings.
DODGERS 8, METS 5
NEW YORK (AP) — Juan Uribe broke out of a long slump with a homer and four RBIs for Los Angeles and Chris Capuano pitched seven solid innings against his former team.
Uribe hit an early two-run double to end a 1-for-38 slide. He added a two-run homer in the ninth inning off 13-game winner R.A. Dickey, who was making his first relief appearance of the season to help an overtaxed Mets bullpen.
Matt Treanor also stopped a slump with a run-scoring hit and the Dodgers won their third straight following a 1-7 skid. Matt Kemp had an RBI triple and Capuano (10-5) struck out nine for his first victory in seven career starts against the Mets.
Los Angeles chased 41-year-old spot starter Miguel Batista (1-3) after three innings.
Ronny Cedeno homered for the Mets, who have lost eight of nine.
REDS 6, BREWERS 2
CINCINNATI (AP) — Ryan Ludwick and Brandon Phillips hit two-run homers to lead Cincinnati.
The NL Central leaders have gone 4-2 since slugger Joey Votto learned he needed surgery for torn knee cartilage. The Reds have won 10 of 12 overall, moving a season-high 14 games over .500.
Ludwick homered as part of a four-run first inning off Yovani Gallardo (8-7). Phillips homered in the eighth off Jose Veras, dropping the defending division champion Brewers a season-high 9 1/2 games out.
The Reds, who won the division in 2010, are 6-2 against the Brewers this season.
Bronson Arroyo (5-6) rebounded from his shortest start of the season, allowing two runs and five hits in six innings.
CARDINALS 12, Cubs 0
ST. LOUIS (AP) — Jake Westbrook allowed three hits over seven innings and St. Louis backed him by tying a 76-year-old major league record with seven doubles.
Rafael Furcal's go-ahead single in the seventh turned out to be a mere appetizer as the Cardinals also matched an 86-year-old franchise record for runs in an inning. St. Louis totalled 10 hits with multiple hits by three players including pinch-hitter Allen Craig, who doubled twice with an RBI.
The Cardinals tied the major record for doubles in an inning by the Boston Bees at St. Louis in the first inning of Game 1 of a doubleheader on Aug. 25, 1936.
They tied the franchise record for runs in an inning set in 1926 against the Phillies, in the third inning of the opener of a doubleheader in Philadelphia.
PIRATES 5, MARLINS 1
PITTSBURGH (AP) — A.J. Burnett remained undefeated at home by pitching 7 2-3 strong innings and Pittsburgh matched a season high with its fourth consecutive win.
Burnett (11-3) allowed one run and eight hits. A homer by Justin Ruggiano was his only blemish as he improved to 7-0 at home this season and Pittsburgh (53-40) moved 13 games over .500 for the first time since the end of the 1992 season.
Garrett Jones had two RBIs and Alex Presley scored two runs for the Pirates, who have the majors' best home record at 31-14. Pittsburgh has won 20 of its past 24 at home and 15 of its past 20 overall.
The Marlins have lost four straight.
The Pirates went ahead during a four-run fourth in which they did not record a hit — the first time in almost 14 years a major league team did that.
Carlos Zambrano (5-8) was charged with five runs (four earned), three hits and six walks with two strikeouts. He has lost five of his past six decisions and has allowed at least three earned runs in each of his past eight outings after doing so in four of his first 11 starts.
ROCKIES 8, PADRES 6, 12 innings
SAN DIEGO (AP) — Jordan Pacheco drove in four runs, including the go-ahead score in the 12th inning, and Michael Cuddyer tied a career high with four hits for Colorado.
The victory snapped the Padres' four-game winning streak and ended the Rockies' three-game skid.
Cuddyer singled off Joe Thatcher (0-3), San Diego's sixth reliever, with one out in the 12th. He was sacrificed to second and came around to score on Pacheco's third hit of the game, a single to left. Ramon Hernandez made it 8-6 when he singled home Pacheco.
Torres (1-0) got the victory with two scoreless innings. Rafael Betancourt, the Rockies' fifth reliever, came on in the 12th to pick up his 16th save.