PHOENIX (AP) -- Mike Cameron's rough road trip took a turn for the better Wednesday night.
"I wasn't trying to think too hard," said Cameron, who was 4-for-23 in the first eight games of the Brewers' 10-game trip that ends Thursday. "It was just a curveball and I put a good swing on it. It ended up being a big hit."
Cameron finished 2-for-4 with two RBIs and Rickie Weeks added his first career pinch-hit home run for the Brewers, who rallied from a 2-0 deficit for their second straight win.
"It was a beautiful game," said Salomon Torres, who allowed two baserunners in the ninth before recording his 15th save in 17 opportunities.
The Diamondbacks (42-43), who left 12 men on base and had two runners thrown out at home, lost for the eighth time in 11 games and dropped below .500 for the first time since opening the season 1-2. Their lead in the NL West over the Los Angeles Dodgers slipped to 1 1/2 games.
"We're going through a tough period where we're coughing up some games where we don't normally give them up," Arizona manager Bob Melvin said. "They got some big hits when they needed it. That was the deciding factor. They got some big hits and we left some guys out there."
David Riske (1-1) earned the win after surrendering a game-tying homer to Justin Upton, his 10th, in the bottom of the eighth. Torres gave up a leadoff single to Orlando Hudson and walked Mark Reynolds with one out before retiring Chris Young on a game-ending double play.
"I didn't deviate from my thought process," Torres said. "I said to myself to keep the ball down, make him hit your pitch."
Branyan reached on an error by Reynolds, who was making his first career appearance at first base after pinch-hitting for Chad Tracy in the seventh. Gabe Kapler sacrificed Branyan to second and Cameron followed with a sharp single to left off closer Brandon Lyon (2-3) to make it 4-3.
"I've got to make to the play," Reynolds said. "It was just a groundball. I should have made the play."
Weeks, who had spent all day Tuesday in bed with the flu, had given Milwaukee a 3-2 lead in the eighth when he drove an 0-2 pitch from Tony Pena six rows into the stands in left for his eighth home run.
"We figured Rickie's a leadoff hitter, let's see if he can't lead off and get on base," Brewers manager Ned Yost said. "He put a jolt into one."
Arizona took a 2-0 lead against Milwaukee starter Seth McClung.
Tracy singled to lead off the second, Young reached on an infield single and Upton was hit by a pitch to load the bases. Miguel Montero followed with a ground single into shallow center.
The Diamondbacks made it 2-0 in the third when Hudson doubled to left and scored on Young's two-out single off second base.
J.J. Hardy drove in Jason Kendall with a sharp single to left in the sixth, pulling the Brewers within 2-1. In the seventh, Kapler tripled to the base of the wall in right-center with two outs and Cameron followed with a bloop single to left off Chad Qualls to make it 2-2.
"It was just one pitch," Qualls said. "I make that mistake and I'm not getting away with it right now."
Yusmeiro Petit, making his first major league start since Sept. 30, retired 15 of the first 16 batters he faced and allowed only three baserunners over six innings.
The Brewers have won 10 of their last 13 against the Diamondbacks. ... Petit had been recalled from Triple-A Tucson on June 27 when RHP Edgar Gonzalez was placed on the 15-day DL. ... Brewers 1B Prince Fielder went 0-for-4 to extend his skid to 2-for-31 over nine games. ... The Diamondbacks, who had four bunt singles in their first 84 games, had two in the first two innings.