CHICAGO — Pablo Sandoval snapped his 0-for-39 skid with a three-run homer, Matt Moore pitched effectively into the seventh inning and the San Francisco Giants beat the Chicago White Sox 9-2 on Friday night.

Denard Span also homered and Brandon Crawford had three hits with an RBI for San Francisco, which has won back-to-back games after losing seven of eight.

Sandoval went 1 for 3 with four RBIs. His previous hit was a single on Aug. 25 at Arizona.

Avisail Garcia homered for Chicago, which has dropped five in a row.

Moore (5-13) allowed two runs and five hits in 6⅔ innings. He won for just the second time in eight decisions.

Lucas Giolito (2-2) gave up five runs, three earned, and three hits in 5⅓ innings. He walked four, struck out five and was ejected by plate umpire Gabe Morales after he was lifted.

White Sox manager Rick Renteria also was tossed, by crew chief Eric Cooper. Giolito had allowed one earned run in 14 innings over his previous two starts.

The 23-year-old right-hander didn’t permit a hit until Crawford singled with one out in the fourth.

Nick Hundley followed with a walk. One out later, Giolito hung a 2-1 changeup to Sandoval, who hit a 405-foot drive deep into the right-field bleachers for a 3-0 lead.

Garcia’s two-run shot in the bottom of the inning made it 3-2.

The Giants added a couple of unearned runs in the sixth for a 5-2 lead.

Buster Posey, who reached on an error by Chicago second baseman Yoan Moncada, scored the first run when the defense was caught napping. With runners on the corners, Crawford took off from first base on a 3-2 pitch to Hunter Pence. The pitch was called a ball, but catcher Kevan Smith threw to second base. Moncada went to tag Crawford as Posey ran home from third.

Crawford then moved to third on a wild pitch by Aaron Bummer and scored on Sandoval’s sacrifice fly.

Crawford had an RBI single in the seventh for a 6-2 lead.

Span hit a solo shot and Hundley added a two-run single in the ninth.

TRAINER’S ROOM

Giants: Injured closer Mark Melancon will have season-ending surgery on his right forearm Tuesday. Melancon has been bothered by chronic compression of a muscle in the forearm throughout the year, and the surgery will aim to relieve it. “After Colorado, we said let’s go ahead and get this thing done for his peace of mind and everybody’s,” manager Bruce Bochy said.

White Sox: LHP Carlos Rodon was placed on the 10-day DL with shoulder inflammation and the team announced he won’t pitch again this season. Rodon had an MRI after being scratched from his scheduled start Thursday. He’ll be re-evaluated next week.

UP NEXT

Chicago right-hander James Shields (2-6, 5.72 ERA) looks to snap an 11-start winless streak Saturday night in the middle game of the series. San Francisco righty Jeff Samardzija (9-2, 4.31) faces his former team for the first time since leaving as a free agent following the 2015 season.