KANSAS CITY, Mo. — The Kansas City Royals took advantage of a pair of errors by the Chicago White Sox to score three times in the eighth inning Sunday and rally for a 7-6 win that avoided a three-game sweep.

The Royals trailed by two when they got consecutive singles by Mike Moustakas and David Lough off ace White Sox reliever Jesse Crain (2-2) to start the eighth. An error by Crain while trying to field a bunt by Elliot Johnson loaded the bases with nobody out.

Crain struck out George Kottaras and Jarrod Dyson to breathe a bit easier, but he walked Alex Gordon to get Kansas City within a run. Alcides Esocbar then slapped a grounder to shortstop that Alexei Ramirez let through to left field, bringing in the go-ahead runs.

While unearned, they were the first runs Crain had allowed in 30 appearances.

Luke Hochevar (1-1) struck out two in a scoreless innings of relief for Kansas City, while Greg Holland pitched a perfect ninth for his 16th save in 18 chances.

Kottaras and Dyson hit back-to-back homers for the Royals, who snapped a four-game losing streak with the kind of scrappy, win-ugly performance that is becoming their hallmark.

Adam Dunn homered and drove in four runs, and Gordon Beckham also drove in a pair for the White Sox, who were trying for their first road sweep since last September.

Royals starter James Shields and White Sox counterpart Dylan Axelrod both endured rough afternoons, though they certainly got an exciting show once they left the game.

Shields threw six straight balls to start the game and things never got a whole lot better, his leadoff walk to Alejandro De Aza and a single later in the first inning turning into two quick runs when Dunn rapped a single off the glove of Eric Hosmer at first base.

The Royals' ace then plunked Alex Rios in the back in the third inning, and Dunn made Shields pay again for his erratic ways with his no-doubt, two-run shot to center field.

It was the 20th homer for the hot-hitting Dunn, who trails only the Orioles' Chris Davis and Blue Jays' Edwin Encarnacion for the most in the American League.

Shields wound up putting the leadoff batter on base in four of his five innings, and needed 97 pitches just to last that long. He departed without finishing six innings for the first time since last July 15 against Boston, a span of 30 consecutive starts.

The former All-Star hasn't won in his last 10 outings.

The Royals got the first run in their comeback in the bottom of the third on Gordon's single, and then pulled even against Axelrod during a three-run fifth inning.

The first two came on their back-to-back home runs — the 26th career homer for Kottaras, who was giving Salvador Perez the day off behind the plate, and just the third career shot for Dyson, who was making his first start since returning from the disabled list on Saturday.

Alcides Escobar kept the rally alive with a double, and Billy Butler's two-out single through the left side of the infield tied the game 4-all and knocked Axelrod from the game.

Beckham's double off Kelvin Herrera in the seventh inning pushed the White Sox back in front, but a bullpen that has been stingy all month finally let them down.

Notes: Kottaras threw out two runners on pitch outs. ... Beckham was back in the lineup after a day off. ... The Royals claimed RHP Maikel Cleto off waivers from St. Louis and assigned him to Triple-A Omaha. They designated OF Quintin Berry for assignment. ... The Royals are off before hosting the Braves for the first time in interleague play on Tuesday. The White Sox also are off before starting a series against the Mets.