Trevor Cahill and four relievers held the Diamondbacks to five hits, and the Giants completed their first three-game series sweep of the season.
Yastrzemski drove a 3-2 pitch from Luke Weaver (1-4) into the Giants' bullpen in center field leading off the sixth for a 2-1 lead. His birthday happens to fall on the same weekend as the birthday of his grandfather, Hall of Famer Carl Yastrzemski.
''You can't write that stuff,'' Mike Yastrzemski said. ''It's just been really fun to have these opportunities and just try to make the most of them. It's been fun and we've been winning games.''
Alex Dickerson added a three-run homer off Hector Rondon in the seventh to provide cushion and make it a 5-1 game. Evan Longoria doubled home a run and Pablo Sandoval had a run-scoring single to round out San Francisco's offense.
On a day the Giants cut one of their most beloved veterans in Hunter Pence, they got yet another big moment from Yastrzemski, a late-blooming outfielder who has flourished since breaking through with San Francisco last season when he hit 21 home runs.
He's hitting .309 this season with a team-high 24 RBIs, and his seven homers are tied with Wilmer Flores for the Giants' lead.
Cahill held Arizona to one hit over 5 1/3 innings, striking out eight, walking two and being charged with one run that scored after he left the game in the sixth.
Caleb Baragar (3-1) got the final two outs of the sixth and earned the win.
Weaver was strong early for the Diamondbacks, facing the minimum through four innings. He gave up two runs over 5 2/3 innings with five strikeouts.
The Diamondbacks have lost five in a row, perplexing to manager Torey Lovullo in that his team had just won six in a row prior to the skid.
''This was an extremely frustrating trip for us,'' Lovullo said. ''Offensively, we just went into a different place than I was expecting. I expect a lot out of this team.''
Giants rookie catcher Joey Bart has impressed with the bat since being called up a few days ago. But he showed some athleticism Sunday in racing all the way over to the third base coach's box to make a falling catch of Stephen Vogt's foul pop in the fifth.
Third baseman Evan Longoria was positioned near shortstop in a shift and couldn't get to the ball.
''He did a weird summersault, Spider-Man catch,'' Cahill said.
The Giants acquired infielder Daniel Robertson from Tampa Bay on Sunday morning in exchange for cash or a player to be named later. Robertson, 26, hit .231 with 16 homers and 72 RBI over parts of three seasons with the Rays. He was designated for assignment last week.
Robertson was a first-round draft pick by Oakland in 2012, at a time when current Giants President of Baseball Operations Farhan Zaidi was part of the A's front office.
Diamondbacks: LHP Madison Bumgarner, who didn't make the trip to San Francisco to face his old team because of a mid-back strain, was scheduled to throw a simulated game at Chase Field on Sunday with the plan of getting him up to 70 pitches.
Giants: RHP Sam Coonrod was reinstated from the 10-day injured list before the game. The reliever missed 21 games with a right lat strain. He posted a 7.36 ERA in four appearances before his injury.
Diamondbacks: RHP Merrill Kelly (3-2, 2.59) takes the hill for Arizona on Monday to open a four-game home series against Colorado. Arizona took two of three at Coors Field earlier this month.
Giants: Manager Gabe Kapler has yet to announce a starter for Tuesday's opener of a three-game home series against the Dodgers, who have taken four of seven from San Francisco so far this season.
More AP MLB: https://apnews.com/MLB and https://twitter.com/AP-Sports
Copyright 2021 STATS LLC and Associated Press. Any commercial use or distribution without the express written consent of STATS LLC and Associated Press is strictly prohibited.