Arizona’s Paul Goldschmidt hits a single in the third inning to go along with a two-run double in the fifth as the Diamondbacks won their second straight after losing five of the previous six.

George Nikitin / The Associated Press

SAN FRANCISCO — Paul Goldschmidt broke out of a slump with two hits and two RBIs to help the Arizona Diamondbacks beat the San Francisco Giants 4-2 on Thursday night.

Martin Prado and Aaron Hill also drove in runs for the Diamondbacks, who won their second straight after losing five of their previous six. Miguel Montero added two hits.

Trevor Cahill (6-10) won his third straight decision since coming off the disabled list. He allowed two runs and six hits in five innings, walking four and striking out three.

Brad Ziegler pitched the ninth for his eighth save.

Pablo Sandoval had two hits and drove in a run for the Giants, who have lost three of four. Hector Sanchez also drove in a run and Brandon Belt had two hits.

Ryan Vogelsong (3-5) lost for the first time since May 15, though he missed 69 games with a fractured right hand. He gave up four runs and eight hits over 4º innings, walking three and striking out three.

Sandoval tripled home a run and scored on Sanchez’s sacrifice fly in the fourth. Diamondbacks manager Kirk Gibson was ejected on the play for arguing the call.

Gerardo Parra, who threw out two other runners on the bases, made a strong throw that appeared to beat Sandoval. Montero held onto the ball as Sandoval crashed into him, sending both players sprawling on the ground.

Plate umpire Tom Hallion called him safe before Sandoval tried to dive back toward home with Montero trying to beat him there.

Vogelsong retired the first two batters in the fifth and then didn’t get another out, giving up four runs and five hits with a walk before he was replaced by Jake Dunning.

Goldschmidt, who was hitless in 16 previous at-bats, doubled home two runs. Prado followed with an RBI double and Hill followed with an RBI single.

Lefty Patrick Corbin will start today for the D-backs. He’s 2-2 in seven career starts against the Giants.