Sandoval started the day with 10 home runs this season. He then hit a two-run shot in the fifth inning, a leadoff drive in the eighth and a three-run homer in the ninth.
Sandoval's only previous three-homer game came in the opener of last year's World Series. He wound up as the MVP of the Series.
The star third baseman also added a single against the Padres.
San Francisco hit six home runs overall. The Giants began the game tied with Miami for the fewest homers in the majors with 80.
CARDINALS 5, REDS 4, 16 innings
CINCINNATI -- Matt Adams' second homer sent St. Louis to a victory over the Reds in 16 innings, protecting the Cardinals' hold on second place in the NL Central.
Adams broke an 0-for-17 slump by connecting in the 14th. After St. Louis let that lead get away, he homered again off Logan Ondrusek (3-1), ending the Reds' longest game of the season.
The Cardinals had dropped the first two games in the series, letting the Reds get within a game and a half for second place. They finish their season series on Thursday. St. Louis leads it 11-8.
BREWERS 9, PIRATES 3
Liriano (15-7), who had allowed five earned runs in his previous four starts, was rocked for seven runs on seven hits, with two walks and two costly wild pitches. The Pirates, aiming for their 82nd victory, twice left the bases loaded and stranded 12 runners.
The Brewers tagged Liriano for five runs on five hits in the third inning to open a 7-2 lead.
Peralta (9-14) allowed three runs on nine hits in six innings, striking out six and walking one.
Pirates All-Star Jason Grilli, who had been sidelined with a right forearm strain, pitched the eighth for his first appearance since July 22.
ROCKIES 7, DODGERS 5
De La Rosa (16-6) allowed two runs and six hits in matching his career high for wins in a season and tying Washington's Jordan Zimmermann for most wins in the National League. De La Rosa went 16-9 in 2009 for the Rockies.
Colorado built an early lead off Edinson Volquez, who was making his first start for Los Angeles after being signed last week by the Dodgers following his release by San Diego.
Volquez (9-11) allowed four runs and six hits in four innings in falling to 0-5 in six starts against Colorado this season.
METS 5, BRAVES 2
Gee (11-9) cruised after he was given a 5-0 lead in the third. The right-hander allowed one run on four hits in seven innings.
The Mets had 12 hits, including 11 in only 4 1-3 innings against Kameron Loe (0-2), who made his first start in the majors since 2007. He filled in for Julio Teheran, who was given a rest -- a possible sign of things to come this month as the Braves move closer to the postseason.
CUBS 9, MARLINS 7
CHICAGO -- Donnie Murphy homered to cap a four-run rally in the seventh inning and the Cubs connected four times to beat the Marlins.
The Cubs avoided a sweep and prevented the Marlins from winning four straight for the first time this season.
NATIONALS 3, PHILLIES 2
PHILADELPHIA -- Jordan Zimmermann became the National League's first 16-game winner, pitching seven solid innings to lead the Nationals past the Phillies.
Zimmermann (16-8) struck out five, walked one and allowed two runs in winning his fourth straight start.
Jake Diekman (1-4) walked the leadoff batter in the eighth, then allowed pinch-runner Jeff Kobernus to score on a fielder's choice for the winning run.
The Nationals sat outfielder Bryce Harper to rest his ailing hip.
DIAMONDBACKS 4, BLUE JAYS 3
Eric Chavez got the final rally started by blooping a single off Luis Perez (0-1) and pinch-runner Adam Eaton moved to third on A.J. Pollock's single off Jeremy Jeffress. Bloomquist then singled through Toronto's drawn-in infield to cap the Diamondbacks' franchise record-tying 21st extra-inning inning game.
Arizona recovered after a shaky first inning by Randall Delgado, tying the game while its pitchers face the minimum over the next eight innings. Will Harris (3-0) worked around a baserunner in the 10th inning to set up Bloomquist's fourth career game-winning hit.
Rajai Davis homered for the second straight game for Toronto.
Copyright 2013 by The Associated Press
This story is from ESPN.com's automated news wire. Wire index