Joe Camporeale-USA TODAY Sports

J.D. Davis ripped the tiebreaking double in the top of the ninth inning to help the San Francisco Giants record a 6-5 victory over the Arizona Diamondbacks on Friday night in Phoenix.

Brandon Crawford, Austin Wynns and David Villar homered as the Giants (74-77) won their fifth consecutive game. Evan Longoria had three hits for San Francisco.

Stone Garrett homered and Jordan Luplow had two hits and two walks for Arizona (70-82), which has dropped seven of its past nine games. The Diamondbacks struck out 16 times.

San Francisco's go-ahead rally began when Mike Yastrzemski singled off Caleb Smith (1-3) with two outs in the ninth. Longoria followed with a grounder to third, but Sergio Alcantara's throw to second was wild and into right field to put runners on the corners.

Davis then hit a sharp two-bagger to left to score Yastrzemski, but Longoria was thrown out at the plate.

Alex Young (1-1) notched the final out of the eighth for the Giants.

Camilo Doval allowed a two-out single in the ninth to pinch hitter Josh Rojas and uncorked a wild pitch to put Rojas in scoring position. He then retired pinch hitter Alek Thomas on a bouncer to first for his 25th save.

San Francisco's Carlos Rodon was charged with four runs and four hits in 4 1/3 innings. He struck out seven and walked three.

Arizona's Tommy Henry served up three homers in 4 2/3 innings. He allowed five runs, six hits and three walks while striking out six.

Crawford hit his ninth homer of the season in the second and Wynns went deep for the second time in the third to give the Giants a 2-0 lead. Garrett tied the score with his fourth homer, a two-run blast in the bottom of the third.

Villar's two-run homer, his seventh of the season, gave San Francisco a 4-2 lead in the fourth. Longoria's RBI single in the fifth pushed the Giants' lead to three.

Emmanuel Rivera's two-run double in the fifth moved Arizona within 5-4. Luplow's run-scoring single later in the inning knotted the score.

Arizona had a chance to take the lead in the eighth when Ketel Marte hit a two-out double against Shelby Miller. Young entered, and Daulton Varsho hit a bullet to right that LaMonte Wade Jr. caught with a leaping grab on the warning track.

More must-reads:

TODAY'S BEST
Ant-Man leads Timberwolves to Game 1 upset of Nuggets
Luis Arraez makes history in Padres debut
Corey Heim dominates Truck Series race at Kansas Speedway while tempers flare on pit road
Lionel Messi sets MLS record with monster game
Watch: Anthony Edwards does it all for Minnesota
Watch: 150th Kentucky Derby ends in three-horse photo finish
Clippers could see nine-time All-Star jump ship this summer
Phillies get rough injury news on Trea Turner
Watch: Yankees star Aaron Judge receives first career ejection after arguing called third strike
Mavericks lose key player for 'significant period of time'
Blue Jays manager John Schneider blasts team after latest loss
Lakers make another big change after firing Darvin Ham
Draymond Green doubles down on Knicks' inability to win a championship
Phillies lose two-time All-Star to injured list
NBA announces punishment for Lakers star over actions in elimination game
Heat may be cooling on Jimmy Butler's long-term future
NFL insider defends former Steelers QB Kenny Pickett from 'bust' label
Nuggets may miss this player as postseason run continues
Report: Russell Westbrook situation 'far more challenging' than previously thought
Kansas City Chiefs release former second-round pick at WR