"What an old school type of effort. He did everything tonight," manager Bruce Bochy said. "It's playing the game the way it's supposed to be played. The pitchers can help themselves, too. A great effort and we needed it. It's nice to get on the board here."
The big hit of the night came in the sixth inning with two outs when Cain drilled a 2-1 sinker down the right-field line to plate two runs.
"That's a huge compliment," said Cain of Bochy's old school comment. "That was the way I was brought up and taught. If things aren't going your way, try to find ways to make it work, find ways to help your team."
The 27-year-old couldn't top his night off by lasting longer in the game because of a high pitch count. He left after throwing 109 pitches.
In the fourth, Cain took a line drive off his shin for the final out of the inning then came out of the dugout with a shin guard and singled to lead off the Giants' next at-bat.
"It didn't bother me," Cain said. "It didn't tighten up that bad; it'll probably be more stiff tomorrow."
Moments after the single, Cain broke up a double play at second base with a hard slide. The out he potentially saved eventually came around to score.
"I always try to when I have a chance. It was a slower ground ball so I had time to get on the second baseman," he said. "That's the nice part about being in the National League, you feel like you can benefit the team in different ways."
In his last start against the D-backs on April 8, Cain allowed five earned runs in six innings and took the loss.
"We know it, we've talked about it," Cain said of the D-backs nine-game winning streak against the Giants. "We felt like we've played good enough to beat these guys, but today we really focused down and we need to carry that over to tomorrow."
The five runs by the Giants were the most the club has scored since May 5 against the Brewers.
Melky Cabrera pitched in with a 3-for-5 night to extend his season-high hitting streak to 10 games.
Batting second for the first time in his 88-game Major League career, Brandon Belt went 1-for-5, but drove in a run and scored a run.
"There are some tweaks I need to make," Belt said. "It's one of those times where you have to keep on adjusting."
D-backs starter Trevor Cahill threw 5 2/3 innings, allowing six hits, walking three and surrendering four runs. The last pitch he threw Cain hit for the double.
"It was middle-in and I was late on it," Cain said. "I hit it where no one was."
Just as they did Friday night, the Giants jumped ahead 1-0 in the first inning. But this time around, they got a little help from the D-backs.
After Gregor Blanco led off with a walk, an errant pickoff throw from Cahill allowed him to advance to third with no outs. The next batter, Belt, grounded out to drive home the run.
The D-backs tied the game at one run apiece in the third before Cabrera hit an RBI double down the right-field line in the fifth to score Blanco, who reached on a fielder's choice after his pitcher singled.
Cain's two out, two-run double in the sixth that put the Giants ahead, 4-1, came after the previous two batters were hit by Cahill pitches.
"It's frustrating and I'm trying to forget about it," Cahill said. "You can't take anything for granted. I had two strikes on the guy [Brandon Crawford] and I end up hitting him. I'm thinking 'The pitcher is coming up,' and he ends up getting a hit."
After the D-backs plated a run with the help of errors from Cabrera and Crawford to make it 4-2 in the seventh, third baseman Joaquin Arias robbed Ryan Roberts of an extra-base hit that would have put the tying run in scoring position with a nifty backhanded snag and throw to first.
"He has great hands, great instincts and a good release," Bochy said. "It seems like he's getting more comfortable. What a play, throw right on the money."
Cabrera added a second RBI double in the ninth before Santiago Casilla recorded the save.