PHOENIX -- Matt Cain did a little of everything. He pitched six strong innings, knocked in a pair of runs, took a nasty shot off the shin, then slid hard into second base.
"What an old-school type effort Cain gave us," Giants manager Bruce Bochy said. "Pitched, swung the bat, ran the bases. Got the big hit we'd been looking for. He just looked very determined out there."
Cain allowed a run and three hits in six innings, striking out eight, walking two and hitting a batter in his first victory in five outings.
Cain called Bochy's "old-school" comment "a huge compliment."
"That's kind of the way I was brought up," he said.
Trevor Cahill (2-4) took the loss as Arizona was beaten for the sixth time in seven games.
"We didn't play well," manager Kirk Gibson said. "We didn't swing the bats well, struck out 11 times and took five of them. They did a good job of pitching us but we really didn't have that many opportunities. We were 0 for 6 on with runners in scoring position. They had a lot more pressure on us."
Cain singled twice. His second brought in two runs after Cahill had hit consecutive batters with two outs in the sixth. Cain said he likes to show that he can do more than just pitch.
"That's the nice part about being in the National League," he said, "is you feel like you can benefit to the team in different ways, whether it's getting a bunt down or doing different things. You always love to be able to contribute when you have a chance to at the plate."
Santiago Casilla pitched a scoreless ninth for his seventh save in eight tries.
San Francisco beat Arizona for the first time since last Sept. 3.
"We know it," Cain said of the Giants' troubles with the Diamondbacks. "We've talked about it. We've had the situation to where we felt like we've played good enough to beat these guys. We need to really focus down and play better. I think that's something we really need to carry over to tomorrow."
Cabrera's RBI double gave San Francisco the lead for good 2-1 in the fifth. Cain started the inning with a single, then Gregor Blanco reached on a fielder's choice. Blanco stole second before Cabrera's double down the right-field line brought him home.
In the sixth, Pagan's leadoff single was erased with a double play, but Cahill hit Manny Burriss and Brandon Crawford -- the seventh and eighth batters in the order -- to bring up Cain, whose single to right ended the Arizona starter's night. Cahill entered the game with a 3-0 record and 1.20 ERA in four career starts against San Francisco.
San Francisco loaded the bases with one out in the seventh, thanks in part to third baseman Ryan Roberts' fielding error, but Joaquin Arias bounced into a forceout at home, then reliever Craig Breslow struck out Burriss looking.
The Diamondbacks cut it to 4-2 in the seventh helped by shortstop Crawford's eighth error of the season and second in as many nights. Jason Kubel doubled with one out and took third when the left fielder Cabrera threw wild to second. After two outs, pinch-hitter Paul Goldschmidt grounded to Crawford, whose throwing error allowed Kubel to score.
The Giants added a run in the ninth when Belt led off with a triple and scored on Cabrera's double.
Third baseman Arias robbed Roberts with a slick fielding play to end the eighth.
Game notes:Cain was in line to win his previous start against Milwaukee with a 3-2 lead entering the ninth, but Giants closer Casilla blew his first save of the season and the Brewers won 4-3 in 11. ... The Chase Field roof was closed when the game began but was opened after four innings. ... The Giants entered the game hitting .207 with runners in scoring position, second-worst in the majors behind Miami's .199. ... Cain's only other win this season came in his second start, a complete game 5-0 win over Pittsburgh on April 13, when he struck out 11 and walked none. ... Barry Zito (1-1, 2.21 ERA) starts for San Francisco in the series finale on Sunday while the Diamondbacks go with Joe Saunders (2-2, 2.50). ... The Giants lead the majors in errors with 37.
- Home Plate Umpire - Brian O'Nora
- First Base Umpire - Chad Fairchild
- Second Base Umpire - Tom Hallion
- Third Base Umpire - Alfonso Marquez