KANSAS CITY, Mo. (AP) — The Minnesota Twins again showed the resilience that has allowed them to avoid a three-game losing streak this season.

Max Kepler’s RBI single drove in the tiebreaking run and Eddie Rosario added a run-scoring hit to cap Minnesota’s three-run rally in the eighth inning, and the Twins beat the Kansas City Royals 8-7 Friday night.

Minnesota scored five runs in the last three innings.

“We never quit,” said Miguel Sano, whose tying home run leading off the eighth inning started the rally.

“I think we needed this win today to get back to the way of playing that we had a couple of weeks ago,” said Rosario, whose third single of the night gave the Twins their final run. “Everybody was encouraging each other in the dugout.”

Ryne Harper (3-0) pitched one-plus inning to pick up the win despite allowing Jorge Soler’s 21st leadoff home run in the bottom of the eighth that pulled the Royals back within one. Taylor Rogers got the last six outs for his ninth save in 11 chances.

Cheslor Cuthbert had three hits and four RBIs — tying career highs in both — for the Royals, who have lost a major league-high 26 games in which they’ve held a lead. Kansas City has been outscored 177-125 after the sixth inning this season.

“Four of the five runs they scored late against the bullpen came on two strikes,” Royals manager Ned Yost said. “We just couldn’t put them away.”

Trailing 6-3 in the seventh — the Twins’ second three-run deficit of the game — they pulled within one on Nelson Cruz’s two-run single.

Sano’s homer off Jake Diekman (0-5) tied the score, and came after he struck out in his previous three at-bats.

“The first couple of at-bats I was struggling like the last few days,” Sano said. “I never put my head down. I come into work every day hard. I had the opportunity in that at-bat and I was lucky. I said I needed to do something, a walk, single, whatever. God gave me the opportunity to hit a homer.”

Pinch-hitter Mitch Garver then walked and Jonathan Schoop singled. Max Kepler’s single to right drove in pinch-runner Willians Astudillo with the go-ahead run, with Schoop advancing to third and Kepler taking second on the throw. After Jorge Polanco and Cruz hit fielder’s choice grounders, Rosario singled to left to drive in Polanco to make it 8-6.

“We had several guys come through at different moments,” manager Rocco Baldelli said. “It came with big hits, with getting on base and with the long ball. Our guys are resilient and they keep it going.”

Royals starter Jakob Junis allowed three runs and six hits in six innings.

Martin Perez gave up six runs — four earned — in five innings for the Twins.

The Royals scored three runs in the first inning for the second straight game. Cuthbert had an RBI double down the left-field line for the first run. With two outs, Humberto Arteaga rolled a grounder to short, but Polanco’s throw pulled first baseman C.J. Cron off the bag and Soler scored. Martin Maldonado singled against the shift to drive in Cuthbert to make it 3-0.

Cron led off the second with a 424-foot home run to center to get the Twins on the scoreboard.

Minnesota tied it in the fifth with two outs. Rosario’s single scored Schoop and sent Cruz to third. Rosario then stole second, and an errant throw by Maldonado allowed Cruz to score the tying run.

Cuthbert’s three-run home run in the fifth gave the Royals a 6-3 lead.

(© Copyright 2019 The Associated Press. All Rights Reserved. This material may not be published, broadcast, rewritten or redistributed.)