SAN FRANCISCO -- Bengie Molina was ready when Giants manager Bruce Bochy called on him to pinch hit.
Molina hit a three-run home run in the eighth inning and the San Francisco Giants rallied for a 4-3 victory over the Arizona Diamondbacks on Wednesday night.
"Bengie is our clean-up hitter," Bochy said. "If he's not in the starting lineup he's the guy I use when the game is on the line. It's hard to get a bigger hit."
Juan Uribe also homered for the Giants, who won their second straight.
Ryan Roberts homered for the Diamondbacks, who lost for the ninth time in 10 games. Gerardo Parra had two hits and drove in a run.
"This one is pretty crushing because we had every opportunity," Arizona manager A.J. Hinch said. "Early in the game we could have added a few runs and we didn't. We did extend the lead but they stayed close enough and it came back to bite us."
Arizona starter Doug Davis took a four-hitter into the eighth inning. He recorded the first two outs before he walked Edgar Renteria and gave up a single to Randy Winn. Reliever Chad Qualls (2-2) came in and gave up Molina's third career pinch-hit homer.
"I was real happy to get ahead of him 0-2 there," Qualls said. "I wasn't even trying to throw a strike there. I had all the weight leaning toward me and I just didn't execute the pitch. Doug threw too good of a game to deserve this. He goes out there and throws a gem for 2½ hours and I go out there and mess it up."
Justin Miller (3-3) pitched the eighth for the win. Brandon Medders earned his first save.
"I know what I am capable of," said Miller, who took a loss in Colorado on Monday night and had not retired the last nine hitters he faced. "I can hear the [boos]. But that wasn't me. All I did was to look forward to the next one."
Medders was not aware he would be the closer.
"I got up with two outs in the eighth inning," Medders said. "That's plenty of time to get ready. It was like a roller coaster if I was going in or not. I saw [Sergio] Romo run down to the pen but I guess he couldn't get ready in time. It was a good opportunity for me. Saves don't mean much to me. It was just a matter of getting three outs."
Davis gave up a pair of hits in the third and then retired 14 of the next 16 hitters before Uribe's homer. He walked four and struck out five.
Giants' starter Jonathan Sanchez went seven innings, allowing three runs and six hits. He walked two and struck out nine.
"Sanchez picked this whole team up in a big way," Miller said.
Roberts led off the game with a home run for the fifth time in his career. He hit an 0-2 pitch into the left field bleachers to give the Diamondbacks an early edge.
Sanchez retired 13 of 14 hitters from the second inning until Justin Upton, who was activated from the disabled list before the game, drew a one-out walk in the sixth.
Sanchez struck out Miguel Montero for the second out but walked Rusty Ryal ahead of Parra's second hit of the game. Alex Romero followed with another RBI single.
"I knew I had to go deep into the game and give some rest for the bullpen," Sanchez said. "I feel pretty good about that."
Parra entered the game with just two hits in his last 23 at-bats.
All seven of Uribe's hits against the Diamondbacks this year have been for extra bases.
The Diamondbacks optioned left-hander Daniel Schlereth to Reno (PCL) to make room for Upton. ... C Chris Snyder was a late scratch from the Diamondbacks' starting lineup. ... The announced crowd of 27,645 is the fifth-lowest attended game at AT&T Park. ... Giants 1B Ryan Garko is hitting .300 (15 for 50) on the road since joining the Giants and is .121 (4 for 33) at home. ... Giants pitchers threw three wild pitches, their most since April 28. ... Molina is 4 for 6 against Qualls.