Logan Webb (2-2) struck out eight in seven innings as the Giants won their fourth straight. Mike Yastrzemski had two hits and scored twice for San Francisco. Brandon Crawford and Joey Bart both drove in runs.
Christian Walker doubled twice and had four hits for the Diamondbacks. Arizona has lost three straight since a six-game winning streak.
Longoria homered on an 0-1 pitch from Arizona starter Robbie Ray in the third after Flores walked. Longoria's 300 home runs are the most by a third baseman in the majors since 2008, according to the Giants.
''I have never really thought about personal numbers, but it is special,'' Longoria said. ''My wife continued to remind me before the year started that I was only three short. She really likes even numbers so I had to make sure I got there. It feels good to have it out of the way, and in a win.''
Giants manager Gabe Kapler was teammates with Longoria when both played for Tampa Bay in 2009. Not much has changed since then, Kapler said.
''Three hundred home runs later, it isn't a surprise, frankly,'' Kapler said. ''He was that good then and he's had just an incredible career.''
Flores followed with a two-run drive into the left-field stands in the fifth. Flores has homered in three consecutive games and has 10 RBIs during that span.
Longoria, who batted behind Flores, joked that Flores is doing too much.
''I'd like him to leave some runners out there for me,'' Longoria said. ''He crushes left-handers. Everybody knew that coming in. He's proven that he can pretty much hit anybody in this league, and what he's doing right now is pretty special.''
The Giants have scored six or more runs in nine of their 12 home games. This time they got quality starting pitching to back it up.
Webb, who set a career high with five walks in his last start, was much crisper against the Diamondbacks. He allowed two runs and five hits, and retired 10 of 11 after giving up an RBI single to Eduardo Escobar in the fourth.
Tony Watson and Tyler Rogers retired three batters apiece to complete the seven-hitter.
While Webb was sharp, Ray (1-3) was not.
Coming off his best start of the season, the Arizona lefty couldn't follow it up. Ray walked five, struck out eight and allowed four runs in five innings.
''He gave us five innings and made some pitches when he had to, but he made a couple of mistakes that resulted in two two-run homers,'' Diamondbacks manager Torey Lovullo said. ''We kept the game within striking distance and then we'd get runners on base that we just couldn't capitalize on. Christian practically carried us and gave us a couple of bright spots.''
NO SIGN OF MADBUM
Former Giants ace Madison Bumgarner - the 2014 World Series MVP - remains back in Arizona rehabbing a mid-back strain, so he won't see his old club this weekend in the D-backs' first visit to Oracle Park during the shortened season.
Bumgarner will throw another simulated game Sunday at Chase Field with the plan of him getting up to 70 pitches as he continues to build up. ''Getting everything moving in a good direction is our priority,'' Lovullo said.
Missing the Giants series might have been tough for the star lefty, who signed an $85 million, five-year contract with the Diamondbacks during the offseason.
Giants INF Yolmer Sanchez was granted his release by the club. Sanchez had been at the alternate training site.
Diamondbacks: LHP Andrew Chafin has a sprain in his left index finger near the knuckle and will wear a splint for the next week before being re-evaluated. He was placed on the 10-day injured list Wednesday and returned to Phoenix for tests and further examination. ... CF Starling Marte got a day off, something Lovullo has been aiming to do with his regulars during this stretch of 17 straight games before Aug. 31.
Giants: Leadoff hitter Austin Slater came out of the game with a groin strain in the first inning while at third base. Slater, who has been nursing a strained right elbow, drew a walk and advanced on consecutive singles before being replaced by a pinch-runner. He will have an MRI on Saturday. . With RHP Reyes Moronta throwing bullpens in Sacramento as he recovers from shoulder surgery, Kapler still believes the reliever might be back sometime next month. ''I think there's optimism about that,'' Kapler said.
Diamondbacks RHP Zac Gallen (0-0, 2.40 ERA) makes his sixth start in search of his first win of the season Saturday. Gallen is the second pitcher since 1913 to make his first five starts without getting a decision and have an ERA of 2.40 or lower. The Giants counter with LHP Tyler Anderson (0-1, 4.84).
More AP MLB: https://apnews.com/tag/MLB and https://twitter.com/AP-Sports
Copyright 2020 STATS LLC and Associated Press. Any commercial use or distribution without the express written consent of STATS LLC and Associated Press is strictly prohibited.