SAN FRANCISCO _ The San Francisco Giants beat the Arizona Diamondbacks 6-2 on Friday night before a home crowd of 41,576.
Starting pitcher Jeff Samardzija, who struggled at the outset, righted himself and pitched into the seventh inning, surrendering just two first-inning runs before giving way to the bullpen.
Samardzija, who had a 5-3 lead when he departed his previous start against Arizona, gave up five hits and the two earned runs in 6 1/3 innings in improving his record to 9-5. Derek Law finished the seventh, stranding two inherited runners.
Sergio Romo, who missed 76 games this season with an injury, pitched a scoreless eighth in his second appearance since coming off the disabled list Monday. In a 20-pitch inning, Romo gave up a line shot single to Paul Goldschmidt but then struck out Jake Lamb swinging, Wellington Castillo looking and then got Chris Herrman swinging.
After Gregor Blanco hit a pinch-hit home run in the bottom of the eighth, his first of the season, Hunter Strickland finished up in the ninth inning in a non-save situation.
The Giants entered the game with a 54-33 record and were attempting to get to a season-high 22 games over .500. Arizona had won 12 of its previous 14 games against the Giants at AT&T Park dating back to last season.
Shortstop Brandon Crawford led the Giants with a two-run home run (his ninth of the season), a single, a double and three RBIs.
In the fifth inning, the Giants took a 5-2 lead when Grant Green drew a bases-loaded walk off Corbin on a 3-2 pitch. It was the last batter Corbin faced, and the close call led to the ejection of Arizona manager Chip Hale.
Giants manager Bruce Bochy was tossed in the second inning.
The Giants scored a pair of unearned runs in the fourth inning, which opened with a Samardzija double down the left field line. He scored on a two-out throwing error by third baseman Jake Lamb, whose throw sailed over the head of first baseman Paul Goldschmidt.
Crawford was next, and his ground single to right brought in the second run.
With one out and Corbin at first after grounding a single to right, Samardzija hit Segura, who had homered on the first pitch of the game. Segura waited a long time before he made his way to first base, where he was checked by the Arizona training staff.
The Diamondbacks didn't score, and when Posey stepped to the plate in the bottom of the inning, Corbin narrowly missed the Giants' catcher with the first pitch and hit him with the second.
Home plate umpire Quinn Wolcott immediately warned both teams. Bochy came out to argue and was quickly ejected.
Next up was Crawford, who launched a two-run home run into the arcade in right field to tie the game 2-2.
The Diamondbacks took a 2-0 lead in the first on Segura's first-pitch home run and a run-scoring single in a 31-pitch first inning by Samardzija.
_The ejection of Bochy was his first of the season.
_Denard Span started in center field after missing the previous six games with a stiff neck.
_First baseman Brandon Belt was grateful to Giants fans who stuffed the cyber ballot box to get him added to the National League All-Star team with 10.4 million votes, beating out Pittsburgh's Starling Marte.
"It's hard to put into words," Belt said. "I just can't believe I'm an All-Star this year ... to step back and think about how many fans voted, how many times they voted, how many messages I got. How their thumbs were numb. It's pretty overwhelming to think about."
Belt walked four times Friday, giving him 53 for the season. His career-high was 56 in 2015.
_Third baseman Matt Duffy (Achilles) was fielding ground balls before infield practice, throwing to Joe Panik (concussion) at second base. Right fielder Hunter Pence continues to improve. Matt Cain (hamstring) was scheduled to throw in Sacramento Friday night, with Kelby Tomlinson (thumb) playing the infield.
"We still have a ways to go, but it's good to see them out there doing baseball activities," Bochy said. "You have to be careful you don't rush them. At this point, you do see the light at the end of the tunnel."
Bochy said he expected to have news regarding rehab assignments for Pence and Duffy on Sunday. It remains to be seen whether Panik, recovering from a concussion, will also get a rehab assignment.