OAKLAND, Calif. (AP) — Marcus Semien’s big swing ended a hectic and roster-changing day for the Athletics and sent the San Francisco Giants tumbling deeper into their season-long abyss.

Semien hit a grand slam off George Kontos in the sixth inning and Oakland held on to beat the San Francisco Giants 8-5 on Monday night, a few hours after shipping ace Sonny Gray to the New York Yankees in the second of two trades orchestrated by the A’s front office.

Jed Lowrie had three hits and an RBI, Ryon Healy added a two-run single and Matt Joyce reached base four times and scored twice to help the A’s get the upper hand in the Bay Bridge Series before a crowd of 38,391.

“I think really the distraction of the day was mitigated by the crowd and playing against these guys,” Oakland manager Bob Melvin said. “We don’t get too many crowds like that on a Monday night so when you do lose a couple guys like Sonny and (Adam Rosales), to be able to go out and have that kind of atmosphere kind of gets you past that.”

Bruce Maxwell drew a leadoff walk from Josh Osich (3-2) to begin the sixth. Pinch-hitter Rajai Davis followed with a one-out single before Osich walked Joyce to load the bases. Kontos replaced Osich to face Semien, who powered a 1-1 pitch over the wall in left-center for his second career grand slam.

“I was just trying to get a good pitch to hit,” Semien said of his fourth home run this season. “I knew Kontos liked his slider so I chased one first and then I just regrouped and tried to see the ball up.”

Paul Blackburn (2-1), making the start after Gray was dealt to the Yankees, allowed five runs over five innings. Blake Treinen retired three batters for his first save in the AL this season.

Buster Posey and Brandon Belt had two hits apiece for the Giants. Posey struck out to end the seventh with the tying run at third.

Three years after winning its third World Series in a five-year span, San Francisco fell to 40-67, the worst record in baseball. The Giants dropped 35 games behind the Dodgers in the NL West — the most they’ve been behind since the final day of the 1946 season.

Manager Bruce Bochy pointed out the nine walks issued by his pitchers, six from the bullpen….