SAN FRANCISCO -- One moment, Mac Williamson hit the go-ahead homer for his first career long ball as tens of thousands cheered him. The next, he misjudged the wind in left field and lost a fly ball for a two-base error that could have cost San Francisco the game.
Only when the bullpen pulled it out could Williamson exhale.
He homered leading off the eighth inning and later got the ball back with a trade of a signed bat and ball, and the Giants held on to beat David Price and the Boston Red Sox 2-1 on Wednesday night to split the quick two-game series.
"The game's humbling, and it couldn't have happened any quicker than it did to me tonight," said Williamson, who was anticipating a cut fastball inside after Price had already struck him out twice with it.
Brandon Belt also connected for the Giants, who finally got to Price (7-3). He struck out seven over eight innings, allowing three hits and two runs with two walks.
The Giants snapped a three-game losing streak.
"To be able to help the team win, not just get my first home run, but have it be a meaningful home run and help the team win, especially at this point in the season, is really special," Williamson said.
Price and Madison Bumgarner faced off in a rare matchup between two of baseball's top left-handers representing each league, to which Boston manager John Farrell said, "It was as billed." Both pitchers surrendered only a home run before Williamson sent the first pitch deep into the bleachers in left field.
"He's facing one of the elite pitchers in the game," manager Bruce Bochy said. "He got enough of it. He's strong."
Cory Gearrin (2-0) struck out two in a 1-2-3 eighth for the win. Santiago Casilla entered and Williamson immediately committed a two-base error when he dropped Hanley Ramirez's leadoff fly in the ninth, the ball glancing off the outside edge of his glove. One out later, Javier Lopez relieved to face pinch-hitter David Ortiz, who walked.
Belt splashed an 0-1 pitch into McCovey Cove for the 69th by a Giants player and first since he did so in September 2014. This was his fifth splash homer, while home run king Barry Bonds hit 35 of them.
This marked the first career start at AT&T Park for Price, who received a $217 million, seven-year contract to join Boston during the offseason.
"It was one pitch. I'm not going to let it snowball," he said. "... It's a loss. You have to take the good with the bad."
After San Francisco's five-game home winning streak was snapped in a 5-3, 10-inning loss Tuesday night, the Giants earned just their fifth victory in the last 14 meetings with Boston and only the third in 11 at AT&T Park.
The Giants have won each of the last nine starts by Bumgarner -- who wasn't happy with his six-inning outing -- and the 2014 World Series MVP's stretch of six straight winning decisions held since an April 20 loss to Arizona.
Williamson became the first Giants player to put his team ahead on a first career home run in the eighth inning or later since John Patterson in the ninth inning on Sept. 1, 1993, at Atlanta.
Red Sox: Brock Holt, sidelined since May 20 with a concussion, will meet the team in Minnesota and the next steps will be determined. He spent Wednesday being examined by the University of Pittsburgh's renowned concussion experts. "He continues to show improvement but is he ready for rehab? The symptoms are there but they're diminishing," Farrell said.
Giants: RF Hunter Pence is set for surgery on his torn right hamstring Thursday in Dallas. ... C Buster Posey sat out a third straight game with an irritated nerve in his right thumb, and with Thursday's off day he have five full days of rest. Posey has caught Bumgarner every game since 2014, 45 straight. ... RHP Sergio Romo (elbow strain) threw up to 90 feet. ... RHP Matt Cain (strained right hamstring) threw a 72-pitch simulated game while OF Angel Pagan (left hamstring strain) ran the bases and might be ready to begin a rehab assignment as soon as this weekend.
Red Sox: RHP Steven Wright (6-4, 2.29 ERA) has thrown a complete game in each of his last three starts heading into his outing Friday at Minnesota.
Giants: RHP Johnny Cueto (9-1, 2.16) pitches Friday's series opener opposite Dodgers ace Clayton Kershaw (8-1, 1.46). He is 2-0 this season vs. L.A. and 4-2 with a 2.43 ERA over his last six facing the Dodgers.
Pillar hits a two-run triple off Harvey
With Matt Harvey back in New York to face his former team, Kevin Pillar cranks a two-run triple as the Mets go on to beat Orioles 7-1.
Conforto makes an incredible diving catch
Michael Conforto makes a diving catch in deep right field.
Short-handed San Diego Padres place outfielder Wil Myers on injured list, add reinforcements
Outfielder Wil Myers was added to the injured list by short-handed San Diego on Wednesday, as the Padres embarked on a doubleheader vs. the Rockies in Colorado.
New York Mets rough up Baltimore Orioles pitcher Matt Harvey in his return to Citi Field
After a warm reception by Mets fans, Orioles pitcher Matt Harvey gave up seven runs on eight hits in just 4 1/3 innings in his return to his old home as Baltimore lost for the fifth time in six games.
Fantasy baseball: Tristan's three to add for Wednesday
Every Wednesday, Tristan will identify players who should be added to rosters and those that are safe to drop to make room for them.
Fantasy baseball daily notes: Pitcher and hitter rankings for Thursday
Prepare your fantasy baseball lineups confidently with our daily preview, including pitcher projections, hitter matchup ratings and more.