Updated

SAN FRANCISCO (AP) Matt Cain hit a three-run homer during his first win in more than two months, and the San Francisco Giants beat the Cincinnati Reds 9-7 on Tuesday night.

Brandon Crawford had three hits and two RBIs, and Buster Posey and Denard Span added two hits apiece for the Giants. San Francisco won for only the second time since the All-Star break.

It had been longer than that for Cain.

The former Giants ace failed to make it past the fourth inning in his three previous starts and wasn't much better against the Reds. He retired nine of his first 10 batters but quickly wore down and left with one out in the sixth after giving up the first of two homers by Adam Duvall.

Cain (2-6) allowed four runs, struck out four and walked one to win for the first time since May 21.

Duvall added his second home run of the game in the eighth. Joey Votto and Jay Bruce also homered for Cincinnati.

The Giants broke out of their offensive funk with 13 hits and nine runs, the most by manager Bruce Bochy's club in nearly a month.

San Francisco scored four times in the second capped by Cain's seventh career home run, his first since July 21, 2012.

The Giants made it 5-0 in the third on Grant Green's fielder's choice groundout with runners on the corners. Umpires initially ruled that Green hit into an inning-ending double play, but Bochy challenged second baseman Brandon Phillips' tag of Belt and got the call overturned.

Cincinnati chipped away behind Votto and Duvall before San Francisco pulled away on Crawford's two-run triple in the seventh.

Bruce and Duvall hit back-to-back home runs in the eighth off Sergio Romo. Duvall's homer was his fifth in four games.

Santiago Casilla allowed a run in the ninth but got three outs for his 22nd save. He struck out Bruce with a runner on to end it.

Reds starter Cody Reed (0-5) allowed six runs over five innings in his first career appearance against the Giants.

HOMER'S HEALTH

Homer Bailey rejoined the Reds before the game following his latest rehab start in the minors and is likely to make his first start in the majors in more than 15 months on Sunday when Cincinnati ends its six-game road trip in San Diego. Manager Bryan Price said the team is monitoring the right-hander's health after he threw 98 pitches for Triple-A Louisville on Monday. ''I think he's fine, I think he's conditioned, I think he's ready to pitch for us, but we won't announce and make that commitment until he gets through the next 48 hours,'' Price said. ''It could be Saturday, but the probability is it's Sunday.''

TRAINER'S ROOM

Giants: 3B Matt Duffy (left Achilles strain) ran the curves around the infield and could begin a rehab assignment this weekend. ... Ehire Adrianza (broken left foot) is getting close to finishing his rehab, but Bochy is unsure what the plans are after that for the infielder.

UP NEXT

Reds: RHP Dan Straily (5-6) pitches the series finale Wednesday afternoon. Straily, who began the season in the bullpen, is holding opponents to a .213 batting average.

Giants: LHP Madison Bumgarner (10-5) faces the Reds for the first time this season. The four-time All-Star has won three of his last four matchups against Cincinnati.