"We certainly had our opportunities," D-backs manager Kirk Gibson said. "There were a lot of plays that we didn't play very well on. We made it harder on ourselves because we didn't capitalize on our opportunities."
The club batted 2-for-16 with runners in scoring position and dropped to two games below .500 with 18 games remaining in the regular season.
Even with the defeat, though, the D-backs remained 4 1/2 games back of the second Wild Card spot thanks to a Cardinals defeat in Los Angeles.
"You can take some positives out of it but right now we need more than that," said D-backs third baseman Chris Johnson, who drove in the team's only two runs Friday.
The D-backs drew three walks and recorded a bunt single off Cain in the first inning but let the Giants ace off the hook when Adam Eaton was caught stealing, Jason Kubel struck out and Justin Upton popped out to end the threat.
The Giants handed the D-backs another prime opportunity to score an inning later when Pablo Sandoval airmailed an easy double-play ball into right field, allowing two runners to reach safely with no outs. But after a sacrifice bunt moved the pair over to second and third, Eaton popped out and Aaron Hill grounded out to spoil the club's second scoring chance.
In total, the D-backs collected four hits and five walks off Cain over his five-plus innings of one-run work.
"We swung the bats pretty well, hit some balls hard. It was a funky game," Johnson said. "That's all we can ask for, especially off a guy like Matt Cain. He's really good. You try to get guys on and get that big hit but tonight they made good defensive plays and kept us off the board pretty much."
Since losing to the D-backs in his first start of the season, Cain has now beat Arizona two straight times and is riding a four-game winning streak overall.
"I had a couple of 0-2 walks and didn't put guys away," Cain said. "Maybe I got a little too fine with some pitches instead of using the advantage of being ahead in the count."
After the D-backs failed to cash in on their early chances, the Giants took advantage of the momentum swing in a big way in the third against Arizona starter Tyler Skaggs.
Aided by a walk, an infield single and a fielder's choice at home plate, the Giants broke the scoreless tie with one out in the frame before Pence broke the game wide open a batter later on his first grand slam in a San Francisco uniform.
"He made a mistake to Pence; that's the big one," Gibson said. "He throws a high fastball right where you don't want to throw it. That was their big blow."
After serving up the critical long ball, Skaggs left the game an inning later, lasting just four innings and surrendering five earned runs on five hits.
"He's young; he's very young," Gibson said. "Look at all the 21-year-olds; they learn a lot of lessons. It's painful because he busts his tail. You hope he has the character that can make him better. If we didn't believe that, he wouldn't be here."
Since allowing only five combined runs over his first three Major League starts, Skaggs has given up 10 runs in his last two outings, tossing just seven innings in the process.
"It's unacceptable on my part the last two outings," Skaggs said. "It's almost embarrassing."
The D-backs finally got on the board in the sixth, but with the bases loaded and nobody out, they only managed to scrape across one run. They added another with two outs in the ninth.
Offering a bright spot for Arizona, Kubel established a club record with 13 outfield assists in a season by gunning down Angel Pagan at first base in the seventh inning.