"Tonight demonstrated how much he has grown as a pitcher," Giants manager Bruce Bochy said. "He could have caved in. It wasn't going his way. He gave us a gutty effort and battled out there as well as you can. For him to be rewarded like this, you are happy for Matt because of the work he has put in."
Cain ended up going 6 1/3 innings to improve to 8-1, which tied him for the National League lead in victories. He allowed six hits and four earned runs, walked four and struck out six.
He won his career-best sixth straight decision and he has pitched at least six innings in all 12 of his starts, except for a rain-shortened, five-inning complete game in his previous outing.
The 24-year-old right-hander knew the game could have turned after that at-bat against Drew, but stayed focused despite the miscue.
"It's frustrating," he said. "They got me. I was like 'Let's go have a good, clean inning,' and I walk the first batter. And then a curveball to Drew and he is a guy who doesn't miss that pitch. Clearly disappointing, but the game isn't over right there. I knew the guys were going to come back for me.
"That was huge for me and huge for the rest of the team."
The offense came right back with a three-run fifth inning to grab a 5-4 lead when first baseman Pablo Sandoval smacked a two-run blast to right field to give the Giants the lead for good. The sixth inning was another three-run spot as the Giants cranked out a season-best 17 hits off four D-backs pitchers, including starter Billy Buckner (2-2).
Sandoval finished 4-for-5 with three RBIs and is hitting .483 (14-for-29) against the D-backs this season with two home runs and six RBIs.
"He's amazing," Cain said. "He just hits. That's what he does."
Bochy said Sandoval's home run off Buckner in the fifth was the swing the Giants needed.
"That was big. Anytime you come back it is a momentum swing," Bochy said. "That ball was up and that was a good at-bat there."
The top four batters in the lineup -- Aaron Rowand, Edgar Renteria, Randy Winn and Sandoval -- went a combined 11-for-18 with six runs and six RBIs.
"We had production throughout the order," the manager said.
The offensive outburst gave Cain time to relax and refocus on his game plan, something he might not have been around for early in his career.
"I had the right ideas of what I wanted to do," Cain said. "My defense picked me up big-time tonight, too. It gave me confidence and the guys came up and gave the runs I needed to get back into a groove."