"Good to see the boys swinging a little bit," said Vogelsong (3-2). "Good sign."
The right-hander allowed three runs in 6 1/3 innings, which hiked his ERA to 2.50. The Giants had totaled 22 runs in his previous seven starts, but this time he took the mound in the seventh with an 8-1 lead.
"Every time he pitches, he really focuses on keeping the other guys really low on scoring runs," said Gregor Blanco, who scored three runs. "We have to support him. That's what we did tonight."
The Giants came into the game leading the majors in stranded runners, but went 7-for-17 with runners in scoring position. Their run total and 15 hits were both season highs.
Pagan had a pair of broken-bat, two-run doubles, while Cabrera had three hits and raised his average to .362.
The Giants' victory came at the start of a four-game series. Miami swept three games in San Francisco early this month.
"You like to see your offense break out," Giants manager Bruce Bochy said. "That's something we haven't done, especially against this club."
Giancarlo Stanton drove in three runs and hit another tape-measure home run for the Marlins. They began the night with the best record in the majors since May 1 but lost their second in a row.
"That's the worst game we've played all year," manager Ozzie Guillen said. "All-around very ugly."
A long, humbling night for Miami included a botched rundown, a throwing error, two wild pitches, 11 men left on base and one pratfall. First baseman Logan Morrison ducked and landed with an awkward flop to avoid being hit in the head by a throw home from right fielder Stanton.
The bizarre moment left both players laughing.
"That kind of game, you're scratching your head," Guillen said. "You have to turn the page as quick as you can."
Anibal Sanchez (2-3) gave up five runs in 5 1/3 innings, his shortest and worst outing this year. He had allowed a total of three runs in his four previous starts against the Giants.
"Sanchez has been tough on us in the past," Vogelsong said. "It was good to see us kind of get to him a little bit."
The game was tied at 1 when the Giants wiggled out of a rundown and went on to score four runs in the sixth. Gregor Blanco tripled and was briefly hung up on a grounder back to Sanchez, but he scrambled safely back to third when catcher Brett Hayes held the ball too long.
"One little play changed the game," Guillen said.
After a walk loaded the bases, Pagan hit a two-run double, another run scored on a wild pitch and Brandon Belt blooped an RBI single over a drawn-in infield to put the Giants up 5-1 and end Sanchez's night.
"A lot of bloopers, a lot of bad luck," Sanchez said. "It's part of baseball."
The Marlins sometimes celebrate big hits by making a "lo viste" sign -- a sideways V over one eye -- and a grinning Pagan borrowed the gesture after he singled home a run in the fourth inning.
Consecutive two-run doubles by Brandon Crawford and Cabrera in the eighth put the Giants ahead 12-3.
Stanton became the first player to homer into the beer garden beyond the 427-foot sign in left-center field some 50 feet above the playing field. It was his 10th homer this season and gave Miami a 1-0 lead in the second inning.
"He's strong," Vogelsong said. "I challenged him, he hit it."
On Monday, a grand slam by Stanton knocked out a cluster of scoreboard lights. He had a shot at his third grand slam of the season in the fifth, but fouled out to end the inning.
Marlins LHP Mike Dunn gave up four runs in one inning, then was optioned after the game to Triple-A New Orleans. ... Vogelsong struck out three times and is 0-for-15 with 13 strikeouts this year. ... Omar Infante had four hits and improved to 7-for-11 (.636) against Vogelsong. ... Giants LHP Javier Lopez caught a pop foul near the backstop after C Hector Sanchez was slow to react. ... The game took 3 hours, 54 minutes. ... Two struggling aces meet Friday when Tim Lincecum (2-4, 6.04 ERA) pitches against Josh Johnson (2-3, 4.82). ... Friday marks the anniversary of Giants catcher Buster Posey's season-ending leg injury last year. He was hurt in a collision with the Marlins' Scott Cousins, now playing in Triple-A.