Updated

The Arizona Diamondbacks twice loaded the bases against Ryan Vogelsong with a chance to add to a one-run lead only to come up empty.

Those blown opportunities proved crucial when Melky Cabrera got going with three more hits to help spark the San Francisco Giants to a 3-1 victory over Arizona on Tuesday night.

"We had our opportunities to beat him and we let it go," manager Kirk Gibson said. "It's as simple as that. Not to take anything away from him, but we're much better than this."

Cabrera got his 50th hit of the month to spark the go-ahead rally and Buster Posey drove in a pair of runs to lead the Giants to a 3-1 victory over the Arizona Diamondbacks on Tuesday night.

Posey drove in Cabrera with an RBI double in the sixth inning to tie the game and followed Cabrera's single in the eighth with a sacrifice fly that scored Ryan Theriot to make it 2-1 and help the Giants win for the 12th time in 18 games.

Cabrera finished with three hits to pass Willie Mays for the most ever in May by a San Francisco player and the second most in any month — one shy of the record set by Randy Winn in September 2005. The Giants have one game left this month.

"When a guy's going like that you just have to kind of minimize the damage because otherwise you're going to walk him, and you don't want to do that," Arizona starter Joe Saunders said. "I don't know in words to explain. Obviously something stupid but he's in a different dimension right now. You just keep making your pitches and hopefully he hits it at somebody."

Theriot started the winning rally by drawing a leadoff walk from Bryan Shaw (1-3), who had not allowed an earned run in his first 10 road outings of the season.

Cabrera followed with a single to right that sent Theriot to third and Posey hit a sacrifice fly to deep right to give the Giants the lead. San Francisco added an insurance run on Joaquin Arias' forceout.

Vogelsong allowed one run in seven innings but got a no-decision for San Francisco. Clay Hensley (2-3) pitched a perfect eighth for the win and Santiago Casilla got three outs for his 14th save in 15 chances.

Cabrera, acquired in an offseason deal from Kansas City for lefty Jonathan Sanchez, leads the majors with 77 hits and 25 multihit contests just 50 games into the season.

"He reminds me of Tony Gwynn," said manager Bruce Bochy, Gwynn's former skipper in San Diego. "That's the type of hitter he is. He takes what they give him. He doesn't try to do too much up there. He has a calmness. He doesn't panic even with two strikes. He's just a great hitter."

Cabrera scored the Giants first run after reaching on a swinging bunt with one out in the sixth against Joe Saunders. He scored on Posey's double but the Giants couldn't get any more despite loading the bases with one out. Brad Ziegler relieved and got Arias hit into a 1-2-3 double play to keep the score tied at 1.

The Diamondbacks struck first when Chris Young walked with one out in the second, moved up on a wild pitch and scored on Josh Bell's single to center field.

They missed a chance to expand the lead after loading the bases with one out in the fourth. Vogelsong recovered to get Bell on a foul popup and John McDonald on an inning-ending groundout.

The Giants failed to capitalize on their bases-loaded chance in the bottom half as Saunders struck out Arias to strand three runners.

Vogelsong escaped a second-and-third, no-out jam in the sixth by getting Paul Goldschmidt and Bell to ground out and then striking out Saunders after an intentional walk loaded the bases. Vogelsong allowed one run and six hits in seven innings, striking out eight.

"It was just a matter of one of those games where you just couldn't buy that big hit," Saunders said. "That happens. We just have to turn the page and try to do a better job collectively tomorrow."

NOTES: Arizona SS Willie Bloomquist was scratched from the original lineup as a precaution because of soreness in his hamstrings. McDonald took his place in the field and Aaron Hill moved up to leadoff. ... San Francisco's Tim Lincecum (2-5) pitches against Ian Kennedy (3-5) for the fourth time the past two seasons in the series finale Wednesday, with the Diamondbacks winning the last two meetings.