SAN FRANCISCO (AP) — Matt Chapman homered twice, including a pivotal drive in the ninth inning that followed a late collapse by Oakland’s bullpen, and the Athletics held on to beat the San Francisco Giants 9-5 on Wednesday.

Homer Bailey pitched seven scoreless innings and singled twice. Robbie Grossman also went deep and made a sliding catch in left, and Matt Olson added a two-run double to help the A’s earn a split of the two-game series between Bay Area rivals.

Mike Yastrzemski homered for San Francisco, which had won three straight.

Chapman homered off Tyler Beede (3-7) in the first and added another solo shot off Trevor Gott in the ninth after the Giants had trimmed a 7-0 lead to 7-5.

It was the third multi-homer game of Chapman’s career. He leads AL third basemen with 27 home runs.

Joakim Soria and Yusmeiro Petit were tagged for five runs in the eighth. Yastrzemski’s three-run homer off Soria made it 7-4. Pinch-hitter Alex Dickerson followed with a groundout that drove in Evan Longoria before Liam Hendriks struck out Kevin Pillar to end the inning.

Hendriks retired four batters for his 13th save.

Bailey (10-8) kept the Giants quiet. The 33-year-old right-hander allowed two hits, struck out seven and walked one in his best outing since being acquired from Kansas City on July 14.

Bailey also drove in Oakland’s first run with an infield single when Longoria fell forward onto the grass while fielding the ball. Bailey’s other hit was a crisp single to right.

Beede allowed four runs and eight hits in four innings. The right-hander is winless since July 14.

HITTING PITCHERS

Before Bailey’s two singles, Oakland’s pitchers had only four hits this season. All four were by Brett Anderson.

ROSTER MOVES

A’s second baseman Corban Joseph was recalled from Triple-A Las Vegas before the game and singled in the eighth. Outfielder Nick Martini was sent down, and catcher Beau Taylor was designated for assignment.

The Giants activated outfielder Alex Dickerson off the injured list. Dickerson had been out since Aug. 1 with a right oblique strain.

TRAINERS ROOM

Athletics: LHP Sean Manaea (shoulder surgery) will make another rehab start with Las Vegas. … RHP Marco Estrada (lumbar strain) will pitch Thursday for Las Vegas.

Giants: INF Pablo Sandoval was placed on the 10-day IL with right elbow inflammation. Sandoval had a cortisone shot and underwent an MRI, but the severity of the injury is unknown. … RHP Johnny Cueto is expected to throw 45 pitches in a rehab start with Class A San Jose on Thursday.

UP NEXT

Athletics: Mike Fiers (11-3, 3.30 ERA) takes a nine-game winning streak into Thursday’s start against Houston. The right-hander had no-decisions in each of his three starts against the Astros this season.

Giants: Manager Bruce Bochy has not announced a starter for Thursday’s game at Arizona.