McCarthy (1-10) allowed five runs and 10 hits in five innings. The 10 hits matched a season high.
After blowing his previous two opportunities, Sergio Romo escaped trouble in a scoreless ninth for his 21st save in 25 tries. With runners at second and third, two outs and Paul Goldschmidt coming to bat, Bochy went to the mound to make sure Romo knew what to do. Hill would be the next batter.
The choice was to go after Goldschmidt.
''It's a tough call,'' Bochy said. ''You're going against the book a little bit.''
Romo gave up a one-out, pinch-hit double to Roger Kieschnick, then Didi Gregorius beat out an infield single. The runners moved to second and third when Gerardo Parra grounded out, bringing up Goldschmidt.
The Arizona slugger hit it hard to right, where Pence tracked it down.
''He (Goldschmidt) is 4 for 10 and Hilly is 0 for 6 (against Romo),'' Arizona manager Kirk Gibson said. ''I am surprised they didn't pitch around him the whole series. ... They got away with it."
Romo's pitch was very hittable.
''He might have got away with that pitch, but he got him out,'' Bochy said, ''and that's a big out for us to end this losing streak.''
Pablo Sandoval singled three times with an RBI and scored a run for San Francisco.
Colvin singled in two runs in the first and drove in another with a ground out after Brandon Crawford tripled to lead off the fifth.
San Francisco first baseman Michael Morse left the game in the bottom of the fifth inning with back tightness after an awkward swing at the plate. Morse said it was nothing serious. Bochy said he'd give him Sunday off and see what happens after that.
Pence got the Giants started with a one-out single up the middle in the first. Buster Posey followed with a single, then Sandoval singled Pence home, with Posey taking third when left fielder David Peralta booted the ball. Crawford drew a two-out walk to load the bases, then Colvin's two-run double made it 3-0.
It was 4-0 after Posey's double and Morse's RBI single in the second. Arizona got two in the second on doubles by Hill, Miguel Montero and David Peralta.
Arizona got two in the fifth to make it a one-run game before Pence's homer provided a two-run cushion.
The Giants called up top 2B prospect Joe Panik from Triple-A Fresno. He made his major-league debut as a pinch hitter in the eighth and walked. ... To make room for Panik, San Francisco optioned OF Juan Perez to Fresno. ... In the finale of the series on Sunday, the Giants send Madison Bumgarner (8-4, 2.85 ERA) to the mound against Arizona's Mike Bolsinger (1-2, 5.70). ... McCarthy has more RBI (three) than wins (one). ... McCarthy's lone victory came on May 3 at San Diego. He also gave up 10 hits, but in seven innings, against the Dodgers on April 11. ... The Giants stranded 10 runners, Arizona eight.