PHOENIX (AP) Evan Longoria's last hit was the biggest one - a tiebreaking homer in the eighth.
He drilled Diamondbacks reliever Archie Bradley's 2-2, 97 mile-per-hour fastball with one out into the outcropping of seats in left-center field. It was Longoria's 12th home run of the season.
''You just try to get the barrel on the ball. I thought it might go,'' Longoria said. ''The wall is pretty high out there so you have to hit it pretty high. I'm glad it just scraped over.''
The Diamondbacks' loss and the Los Angeles Dodgers' win Sunday created a tie for first place atop the NL West between the two teams.
Bradley (3-3) entered the game leading the NL in holds with 30. He had not allowed a run to the Giants in 12 straight games against them.
''Archie just made a mistake to a really good hitter,'' Diamondbacks manager Torey Lovullo said. ''I thought he threw the ball well outside of that.''
Right-hander Ray Black (1-0) earned his first major league win with a scoreless seventh inning. The Diamondbacks loaded the bases in the bottom of the eighth with two outs against Giants relievers Tony Watson and Sam Dyson, but Dyson got Ketel Marte to fly out to end the inning.
Will Smith retired the Diamondbacks in order with two strikeouts in the ninth for his seventh save.
''The pitching was there and we needed it,'' Giants manager Bruce Bochy said.
Giants All-Star catcher Buster Posey returned to the lineup after missing Saturday's game for concussion testing. Posey played first base and reached base twice.
Both starters lasted 5 1/3 innings in no-decision efforts. The Giants' Derek Holland allowed two runs on three hits and struck out six with two walks. The Diamondbacks' Robbie Ray walked four and struck out eight, giving up two runs on seven hits.
Steven Souza Jr.'s third home run of the season sailed into the left field seats and gave Arizona a 1-0 lead in the second inning. But the Giants tied the game in the third.
Longoria, who had three hits on the day, beat the defensive shift with a two-out single to drive in Andrew McCutchen. He has reached base in eight of his last nine plate appearances.
Marte bounced a single to right field to drive in Eduardo Escobar from second base for a 2-1 Diamondbacks lead in the fourth.
The Giants had a chance for a big inning in the sixth. Longoria led off with a double and scored on Nick Hundley's single, but Hundley was thrown out by left fielder David Peralta trying to reach second base on the hit. Austin Slater followed with a single and reached third base before the inning ended with Yoshihisa Hirano striking out Gorkys Hernandez.
Ray said he was thinking about a little boy he accidentally hit with an errant throw during pregame long toss. The boy, whom Ray believed to be 4 or 5 years old, was fine and did not have to leave the stadium.
''If he wouldn't have been all right, I don't know how I would have went out there and pitched today,'' Ray said.
Ray and catcher John Ryan Murphy spoke to the boy and the two players signed autographs for him. ''Him staying there and watching the game, that was big for me from a mental standpoint,'' Ray said.
The Giants finished a six-game road trip to San Diego and Arizona with a 4-2 record after earning a series split against the Diamondbacks. It's their first winning road trip this season and the first since going 4-2 at Pittsburgh and Detroit last year from June 30 to July 6.
''It has been a while for us,'' Bochy said. ''It's good to have a little success on the road.''
Giants: Posey, who left Friday's game in the third inning after he took a foul ball to his mask, could catch in Monday's game if he continues to feel OK, Bochy said.
Diamondbacks: IF Deven Marrero (strained oblique) played nine innings of a rehab assignment game with Triple-A Reno Saturday and was scheduled to play again Sunday. ... OF Jarrod Dyson (groin strain) is hitting and throwing, but not doing serious running yet.
Giants: RHP Dereck Rodriguez (5-1) is scheduled to pitch the opener of a two-game series against the Houston Astros Monday in San Francisco.
Diamondbacks: RHP Zack Godley (12-6) pitches the series opener against the Philadelphia Phillies Monday at Chase Field.
More AP baseball: https://apnews.com/tag/MLBbaseball
Copyright 2018 by AP. Any commercial use or distribution without the express written consent of AP is strictly prohibited.