Giants 5, Diamondbacks 4

SAN FRANCISCO -- Buster Posey tied the game with a two-run home run in the eighth inning and Brandon Belt won it with an RBI single in the ninth as the San Francisco Giants outlasted the Arizona Diamondbacks 5-4 Monday night in the opener of a three-game series between the second- and third-place teams in the National League West.

Belt, who entered the game in the top of the ninth as part of a double-switch, sliced the game-winner over shortstop against Arizona's fourth pitcher, Tony Sipp (1-1), scoring Andres Torres from second base and strengthening their hold on second place for the Giants (13-7).

Torres had led off the ninth with a single, his second hit of the night. He was sacrificed to second by Brandon Crawford, setting up the game-winner.

Sergio Romo (1-1), who retired the only batter he faced -- pinch-hitter Eric Hinske -- to end the top of the ninth inning with the potential go-ahead run at second base, got the win for the Giants.

Neither starter, Arizona's Wade Miley and San Francisco's Ryan Vogelsong, factored in the decision, which extended the Giants' home winning streak to seven games while improving their record against NL West teams this season to 9-1.

Miley, who took a shutout into the seventh inning against the New York Yankees in his previous start, surrendered three doubles and two runs to the Giants' first four batters before settling down and not allowing the home team to add to its total before turning things over to the Diamondbacks bullpen in the seventh as Arizona (10-9) attempted to move within a half-game of San Francisco in the standings.

Posey feasted on a fastball by Arizona's second reliever, David Hernandez, and took it over the 399-foot mark with Pablo Sandoval aboard in the eighth to erase a 4-2 Giants deficit and set up the exciting finish.

The home run was the second in two days for Posey, who hadn't homered in the Giants' first 18 games.

Miley and Eric Chavez hit solo homers for the Diamondbacks, and former Giants outfielder Cody Ross had a two-run single and a key defensive play as Arizona built the two-run lead it took into the eighth inning.

Miley, who had gone 37 at-bats bridging the 2012 and '13 seasons without a hit, shocked the sellout crowd at AT&T Park with a blast into the right-field pavilion to break a 2-2 tie in the fifth inning. It was the first career homer for last year's National League Rookie of the Year runner-up.

Chavez gave the left-hander another run of breathing room in the sixth when he went the opposite way to left field on a backdoor curve ball for his second homer of the season and a 4-2 lead.

Ross' catch might have been even more important than the Arizona home runs. He took at least a double and probably an RBI away from Posey when he dove onto the warning track near the right-field foul pole and snatched the bid for extra bases with Marco Scutaro prepared to circle the bases from first.

Had the ball fallen, the Giants likely would have been within 4-3 with one out and the potential tying run in scoring position. Instead, Miley faced Hunter Pence with just a runner at first and retired him on a grounder to second.

Miley left with the potential tying runs on base and two outs in the seventh. Brad Zeigler, making his league-leading 12th appearance, needed just one pitch to induce Angel Pagan to ground to first base to end the threat.

Both starting pitchers settled down after rocky starts, with neither team recording a hit for three innings after each had three in the first inning alone. Miley's home run leading off the fifth snapped that string.

The Diamondbacks wasted no time jumping on Vogelsong, who entered the game having surrendered the fourth-highest batting average (.301) among National League starters. Gerardo Parra smacked the second pitch of the game into center field for a single and, two pitches later, Martin Prado executed a perfect hit-and-run, sending Parra to third with a sliced single to right.

Paul Goldschmidt walked to load the bases. After Miguel Montero struck out, Ross blooped a two-run single over shortstop to put the Diamondbacks on top.

Four Giants hitters into the bottom of the first, the score was tied. Marco Scutaro, Pablo Sandoval and Buster Posey all reached the fence with consecutive one-out doubles, the latter two hits producing runs and tying the game at 2-2.

NOTES: The Diamondbacks' Miley has been the ultimate hot-and-cold hitter in his brief career. He enjoyed a rarity for a pitcher -- an eight-game hitting streak in which he went 9-for-20 -- early last season, but finished his rookie campaign in an 0-for-32 slump. He had opened the 2013 season 0-for-5 before taking Vogelsong deep. ... It was clear from the get-go that the Giants weren't going to let Goldschmidt, one of their biggest nemeses, beat them if they could help it. Vogelsong walked the slugger his first two times at the plate and hit him the third time. ... The Giants are four games into a stretch of 15 consecutive games against NL West competition. They entered Monday's game with an 8-1 record against division foes. ... Giants first-base coach Roberto Kelly will miss the entire Arizona series as he attends a graduation in Panama. Special assistant Shawon Dunston coached first base Monday on a "trial" basis.