Matt Davidson homered for the second time in two games at Wrigley Field and drove in the go-ahead run with a sacrifice fly, and Lucas Giolito survived seven walks and three wild pitches over 5 2/3 innings Sunday as the White Sox avoided a series sweep with a 5-3 victory over the Cubs.

The Sox (10-27), who were off to their worst start in franchise history, snapped a seven-game losing streak and won for the second time in their last 13 games. The Cubs (21-16) had a five-game winning streak snapped.

Giolito, who threw 100 pitches with 50 for strikes, was especially wild in the first inning when he walked three and threw two wild pitches. Javier Baez drove in two runs in the first with a two-out single, one of only two hits allowed by the Sox right-hander.

After walking the first two batters and an RBI double by Ian Happ in the fourth, Giolito escaped with no further damage as first baseman Jose Abreu fielded Kyle Hendricks’ ground ball and threw out Addison Russell at home, then retired Ben Zobrist on an inning-ending double play.

Davidson cut the lead to 2-1 against Hendricks with his 11th home run, and after Nicky Delmonico tied it with a triple driving home Abreu (single) from first in the sixth, Davidson hit a go-ahead sacrifice fly to the warning track in left.

In the seventh, Tim Anderson led off with a walk against left-hander Brian Duensing after falling behind 0-2 in the count, was bunted to second by catcher Omar Narvaez and scored on Leury Garcia’s single to left, giving the Sox a 5-3 lead.

Nate Jones, after blowing a three-run lead in the ninth inning against the Pirates in his last outing Wednesday, pitched a perfect eighth, and Bruce Rondon struck out Addison Russell and Ian Happ in the ninth to collect his first save as a White Sox.

The Cubs (21-16) stole five bases against Giolito and Narvaez.