Hector Sanchez hit a three-run homer, Pablo Sandoval had four hits and three RBIs, and
Brandon Belt had four hits and scored four runs for the Giants, who set season highs for runs and hits (19).
Justin Ruggiano homered twice and drove in four runs for Miami.
Christian Yelich and Placido Polanco each had three hits.
San Francisco's offense broke loose after averaging 2.73 runs per game since the All-Star break, the second-fewest in the majors.
The Marlins scored their second-most runs since June 2.
Both starting pitchers struggled.
Chad Gaudin allowed eight runs and 11 hits in four innings for the Giants, while Marlins right-hander Nathan Eovaldi (2-3) gave up 11 runs -- nine earned -- in three innings.
Sandy Rosario (3-0) pitched two scoreless innings for the win.
The Giants jumped out to a 4-0 lead in the first keyed by a two-run double from Sandoval.
Pence, who drove in a run in the first on a grounder, delivered a two-run double in the second and Sandoval followed with an RBI single to stretch the lead to 7-0.
Miami cut the deficit to 7-4 in the third on a two-run double by Logan Morrison and RBI singles by
Donovan Solano and Polanco.
Polanco left in the eighth when he was hit in the back of the head by a pitch from
Pence came through again in the fourth with an RBI double followed by a three-run homer by Sanchez to extend the lead to 11-4, ending Eovaldi's night.
Gregor Blanco added an RBI single later in the inning.
Despite the large deficit, the Marlins fought back again beginning with a solo homer and a two-run double by Ruggiano, who came off the bench in a double switch, to pull to 12-7. Yelich and Solano followed with RBI singles in the fifth to make it 12-9.
Through five innings, the teams combined for 21 runs and 29 hits as each team batted around twice.
Belt and Pence hit back-to-back RBI triples in the seventh to push the lead to 14-9.
Ruggiano hit his second home run of the game in the bottom of the ninth.
NOTES: Ruggiano homered for the first time at Marlins Park after hitting 12 away from Miami. ... Belt extended his hitting streak to 11 games with a single in the first. ... Miami reliever Arquimedes Caminero made his major league debut in the eighth. ... San Francisco's previous high in runs this season was 10 (done seven times) and hits was 17 (three times). ... The Giants will send RHP
Matt Cain (7-8, 4.44 ERA) to the mound on Saturday to face Marlins RHP
Henderson Alvarez (2-1, 3.18).