SAN FRANCISCO -- Paul Goldschmidt and Martin Prado drove in three runs with back-to-back doubles in a four-run fifth inning as the Arizona Diamondbacks rallied following the ejection of manager Kirk Gibson for a 4-2 victory over the San Francisco Giants in the opener of a four-game series Thursday night.
The win opened a seven-game road trip and allowed Arizona to stay within 7 1/2 games of the Cincinnati Reds, who also won Thursday, in the race for the second wild-card playoff spot in the National League.
Trevor Cahill (6-10) ran his post-All-Star Game record to 3-0 despite giving up six hits and four walks in five innings. Cahill managed to hold the Giants to two runs over that stretch, with the second of those runs leading to the ejection of Gibson after a controversial safe call at home plate.
Diamondbacks relievers Tony Sipp, Will Harris, Joe Thatcher and Brad Ziegler held the Giants in check over the final four innings, allowing three hits and a walk but no runs. Ziegler closed with a 1-2-3 ninth, recording his eighth save.
The Giants brought the potential tying run to the plate in three of the four innings against the Arizona bullpen, but two double plays -- the Diamondbacks' second and third of the game -- minimized the damage.
Ryan Vogelsong (3-5) took the loss for the Giants, who were hoping to win a third consecutive home game for the first time since May.
The Diamondbacks out-hit the Giants 10-9, with Arizona's Adam Eaton, Goldschmidt, Aaron Hill and Miguel Montero, and San Francisco's Marco Scutaro, Brandon Belt and Pablo Sandoval recording two hits apiece.
Eaton had two of the Diamondbacks' four doubles.
The Diamondbacks had been shut out on three hits for 4 2/3 innings before completely turning the tables on Vogelsong with five hits in a six-batter sequence that sent the right-hander to the showers in the top of the fifth.
Down 2-0, Arizona got two-out doubles from Eaton, Goldschmidt and Prado in a four-batter flurry that produced three runs. Goldschmidt's double drove in two, and Prado's liner to right-center broke a 2-2 tie.
Hill capped the four-run uprising with an RBI single to left field. When Montero followed with another single, Vogelsong was pulled in favor of right-hander Jake Dunning.
Vogelsong gave up four runs on eight hits in his 4 2/3 innings. He walked three and struck out three.
Gibson's ejection came after television replays showed home plate umpire Tom Hallion erred in calling Sandoval safe at home plate after he had tagged from third base on Hector Sanchez's sacrifice fly to right field.
Sandoval, who homered three times in the Giants' 13-5 win Wednesday in San Diego, got the Giants on the board in the bottom of the fourth inning with a booming triple off the base of the wall at the 421-foot mark in right-center field. The blast scored Hunter Pence from first base.
When Sanchez followed with a flyball to medium-deep right field, Sandoval lumbered home and arrived at the same time as right fielder Gerardo Parra's strong throw. Sandoval collided with Montero, the Arizona catcher, and was ruled to have tagged home plate ahead of Montero's tag, increasing the Giants' lead to 2-0.
Replays showed that Sandoval in fact never touched the plate and was tagged during the collision by Montero. When both players scrambled back toward the plate following the collision, Montero tagged Sandoval again, but Hallion signaled that the Giant already had touched the plate safely.
Gibson questioned the call briefly, then returned to the dugout. But one pitch later, apparently after having heard the result of the TV replay, Gibson barked at Hallion from the dugout and was ejected, his third of the season.
The Giants nearly scored an inning earlier, but another on-the-fly throw from Parra to the plate following a two-out Belt single retired a sliding Brandon Crawford by a couple of feet.
NOTES: Parra also threw out Belt trying to stretch a single into a double on a fifth-inning shot off the right-field fence. The two outfield assists gave him 13 for the season, the second-most among all major-leaguers. ... Giants C Buster Posey had X-rays taken before the game on his bruised right ring finger, which was injured Tuesday when hit while attempting to prevent a wild pitch. No results were immediately available, but Posey was held out of a second consecutive game as a precaution. ... Despite an 8 1/2-game difference in the standings in Arizona's favor, the Giants entered the game with a far better record within the National League West (33-26) than the Diamondbacks (26-29). ... By virtue of having taken two of three in Arizona last week, the Giants began the four-game set with a 10-5 head-to-head edge and having already clinched the season series.