But starter Madison Bumgarner, who blanked Arizona on three hits through five innings, failed to retire a batter in the sixth. Trailing, 9-0, the D-backs scored four runs and had two men aboard before Javier Lopez fanned Didi Gregorius to end the rally.
The Giants weathered adversity before that. Pablo Sandoval departed in the third inning after aggravating his strained left foot, renewing the Giants' concerns over their slugging third baseman.
Nevertheless, the Giants accomplished much with a single victory.
They won on the road, where they own a limp 11-18 record.
They blunted the momentum of first-place Arizona, which leads them by 2 1/2 games in the National League West.
And their lineup, which now features Posey batting third instead of fourth, revived itself. Each starting position player collected at least one hit except Andres Torres, and he managed to drive in a run and score another. San Francisco matched season highs with its double-figure run total and its fourth-inning bonanza.
But Pence, who hit his team-leading 10th homer and scored three runs, brushed aside the notion that manager Bruce Bochy's decision to switch Posey to the third spot in the order galvanized the ballclub.
"I don't think you can ever say that we have to pick it up because every single day you're trying to give it everything you have," Pence said. "There's not like a moment where you're [saying], 'OK, I'm going to go harder now.' How do you go harder than going your hardest all the time? Wherever [Bochy] puts us, we just go out there and comopete that day as hard as we can. All day, every day. There's [never] anything else."
Shortstop Brandon Crawford embodied the unsinkable effort Pence cited by rapping a career-high four hits. Facing Arizona left-hander Patrick Corbin in Friday's series opener, Crawford struck out twice before Joaquin Arias pinch-hit for him. Saturday, he was the game's most prolific player.
"I have to treat it like it's a new day," Crawford said. "And it is."
The Giants' effort began with their most compelling moments of the evening as they hustled for a pair of second-inning runs.
Pence, who's 12-for-12 in stolen-base tries, opened the scoring against Arizona starter Trevor Cahill with some impetuous baserunning. Pence reached base on a fielder's choice, stole second base and had third base pilfered when Arizona catcher Miguel Montero's throw one-hopped third baseman Martin Prado and skipped into left field. The error scored Pence, who was merely trying to reach third to capitalize on the potential for a wild pitch.
"I know [Cahill] throws that heavy sinker and there's a lot of balls in the dirt," Pence said. "They really weren't holding me on and he was kind of lifting his knee up, so I kind of gambled on timing his leg lift and got a pretty good jump."
Torres scored the next run with an adventurous dash from first base on Crawford's one-out double. Racing to beat right fielder Gerardo Parra's one-hop throw, Torres lunged past Montero and scraped home plate with his left hand as he dove headfirst. Umpire Greg Gibson, who had a clear view of the play, made the "safe" call, though Montero insisted that he brushed a tag on Torres' left shoulder blade. Television replays were inconclusive.
The Giants had lost five of Bumgarner's previous six starts. But they made him a winner by victimizing Cahill, who allowed eight runs and nine hits in 3 2/3 innings.
"He didn't have a lot of movement tonight," D-backs manager Kirk Gibson said. "He was struggling to throw the ball on the corners today and they were swinging the bats good. You have to give them a little bit of credit. They just beat on us."