PHOENIX -- Hunter Pence hit a grand slam, Matt Cain dodged trouble for five-plus innings and the San Francisco Giants beat the Arizona Diamondbacks 6-2 on Friday night.
Cain (14-5) walked three in the first and stranded five runners over the first two innings. He failed to make it through six innings for the second time in his last three starts.
The right-hander allowed four hits, walked a season-high five and also hit a batter. He was charged with one run and struck out two.
Buster Posey and reliever Santiago Casilla each drove in a run for the NL West-leading Giants, who won for the third time in four games and are 11-5 in their past 16.
Chris Johnson drove in both runs for the Diamondbacks. Tyler Skaggs (1-2) allowed five runs and five hits in four innings after lasting only three innings in his previous start against San Diego on Sept. 7.
Cain loaded the bases in the first and allowed the first two runners to each in the second but escaped without surrendering a run.
Skaggs got into trouble in the third, and the Giants capitalized.
Cain had a leadoff walk and moved to second on Marco Scutaro's one-out infield single. After Pablo Sandoval singled to center to load the bases, Buster Posey hit a grounder to third and Cain slid under Dan Wheeler's throw on a close play to make it 1-0.
Pence followed with a long drive into the left-field stands for his fourth homer since he was acquired from Philadelphia at the trade deadline. It was No. 21 overall for the season.
The Diamondbacks finally broke through in the sixth. Cain hit Miguel Montero in the foot and Justin Upton singled to right. Cain then gave way to Jose Mijares, who yielded an RBI single to right by pinch-hitter Chris Johnson.