PHOENIX (AP) — Madison Bumgarner worked through traffic in five innings to out-pitch Zack Greinke in a duel of aces, lifting the San Francisco Giants to an 8-1 victory over the Arizona Diamondbacks on Thursday night.

Bumgarner (4-4) pitched with runners on in every inning, yet limited the Diamondbacks to a run on seven hits. He stranded nine runners and struck out five.

Evan Longoria hit a solo homer off Greinke (12-6) and San Francisco broke open a close games five runs in the eighth inning. Austin Slater had two RBIs and scored three times for the Giants, who have won four straight.

Greinke gave up two runs on four hits and struck five in six innings to lose for the first time in nine starts.

Arizona's David Peralta had four hits after missing the previous two games with right shoulder tightness.

Greinke, NL pitcher of the month for July, went 7-0 with a 1.53 ERA and 53 strikeouts in eight starts since June 18.

The right-hander had been using his slow curveball effectively this season, but Longoria took advantage of one in the first inning, hooking a 69 mph pitch just inside the foul pole in left for a solo homer.

Bumgarner escaped a bases-loaded jam in the first inning, thanks to a diving catch by Longoria at third with one out. He allowed a sacrifice fly in the second to work through more traffic, then stranded runners at second and third the next inning.

Bumgarner helped himself with a run-scoring single in the fifth inning off Greinke and pinch hitter Hunter Pence put the Giants up 3-1 with a sacrifice fly in the seventh.

DIAMONDBACKS MOVES

Arizona optioned RHP Silvino Bracho to Triple-A Reno to make room for the return of RHP Brad Ziegler. The Diamondback brought back their former closer in a trade-deadline deal with the Miami Marlins.

TRAINER'S TABLE

Giants: INF Pablo Sandoval will miss the rest of the season with a right hamstring tear suffered while sliding at home plate against San Diego on Sunday. Manager Bruce Bochy said he will require surgery.

Diamondbacks: 3B Jake Lamb opted to have season-ending surgery on his left shoulder to repair fraying of the rotator cuff. He was not in pain, but the damage limited his ability to swing a bat.

UP NEXT

Diamondbacks LHP Patrick Corbin is second in the NL with 166 strikeouts heading into Friday's game against the Giants. San Francisco will send RHP Chris Stratton to the mound after a season-ending injury to Johnny Cueto forced manager Bruce Bochy to juggle his rotation.

___

More AP baseball: https://apnews.com/MLBbaseball