AP Sports Writer
PHOENIX (AP) -- The Arizona Diamondbacks overcame Ian Kennedy's shaky start with three homers in one inning.
They could barely get another hit, much less another homer the rest of the night.
Jason Kubel hit a two-run homer in the fourth inning, and Eric Chavez and Martin Prado each added solo shots, but Arizona's offense all but shut down over the final five innings in a 6-4 loss to the San Francisco Giants on Monday night.
"We hit the ball out of the ballpark, we tied it up and they didn't die," Arizona manager Kirk Gibson said. "It went down to the end but it just wasn't our night."
San Francisco scored three runs off Kennedy the first two innings, including a solo homer by Brandon Belt in the second. Arizona hit three homers while scoring four runs off Matt Cain to go on top, but the Giants fought back in the eighth against Brad Ziegler (1-1).
Nick Noonan, a replacement after Pablo Sandoval left with discomfort in his right arm, got it started with a leadoff double. Ziegler then loaded the bases with a pair of walks and Belt came through with the hit the Giants had been waiting for, lining a two-run single up the middle to break a 4-all tie.
Marco Scutaro sparked San Francisco from the No. 2 spot with three hits and two runs. Jean Machi (1-0) came in for Cain and pitched a perfect seventh inning for his first major-league win. Sergio Romo closed it out in the ninth for his ninth save.
This was just what the Giants needed to end a frustrating five-game losing streak.
"A much-needed win," Giants manager Bruce Bochy said. "The boys battled hard. You have a lead, they come back to take the lead and that can be deflating. But they kept grinding."
A three-time All-Star, Cain finally got some run support, but continued to struggle with the long ball.
The Giants scored three runs in his first five starts and matched that in the first two innings.
San Francisco scored a pair of runs off Kennedy in the first inning on a sacrifice fly by Hunter Pence and Gregor Blanco's run-scoring single. Belt led off the second with a drive to right to make it 3-0.
Cain allowed six homers in his previous three starts, and the balls kept flying over the walls in the fourth against Arizona.
He walked Cody Ross to lead off the inning and Kubel sent the next pitch over the wall with a towering shot to right. Chavez tied it two pitches later with a line-drive solo shot that cleared the wall in left.
Prado hit a third homer in the inning -- a first for Arizona since Aug. 11, 2010, at Milwaukee -- when he drove a 1-2 pitch that Cain left over the plate near where Chavez's homer landed.
Once cruising, Cain found himself trailing 4-3 after Arizona's homer barrage.
Cain allowed five hits, struck out six and walked four in six innings. He didn't figure in the decision, though, after Sandoval hit a tying run-scoring single in the fifth.
San Francisco's pitchers have allowed 28 homers in 26 games.
"It's fair to say he didn't have his best stuff, but he was battling well," said Bochy, who was ejected in the fifth inning after arguing a double-play call at first base. "That one inning, they took advantage of some pitches and in this ballpark, it can happen fast, which it did. But he regrouped and got us through six."
Kennedy also battled back after his early troubles. He allowed four runs and seven hits in seven innings to remain winless in his five starts since Opening Day.
"It was one of those days you feel right away that you don't have your best stuff and it is going to be a battle," Kennedy said. "Even after the first hitter, I knew I wasn't as sharp. I kept them close. I know Matt is a real good pitcher, but I believe in our offense so I wanted to keep it close as long as possible and we would score some runs."
They never did, giving the Giants a much-needed win.
NOTES: Arizona RHP Daniel Hudson threw about 30 pitches in a simulated game and another 20 during warmups in the latest step toward his return from Tommy John surgery last season. The Diamondbacks hope to have him back before the All-Star break. ... Arizona OF Gerardo Parra went 0 for 5 to end a 13-game hitting streak. ... Giants C Buster Posey extended his hitting streak to 10 games. ... Giants LHP Madison Bumgarner will be looking to start the season 4-0 against the Diamondbacks on Tuesday. He received a no-decision in his last start, allowing a run in 7 2-3 innings against the Diamondbacks on Wednesday. ... Arizona RHP Trevor Cahill will be trying for his second straight win Tuesday against the Giants after opening the season with three straight losses.
Copyright 2013 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.