KANSAS CITY, Mo. (AP) It has been one rough year for the Kansas City Royals.

Not this night, though. This one was fun.

Salvador Perez capped Kansas City's five-run ninth inning with a game-ending grand slam, lifting the Royals to an 8-4 victory over the Minnesota Twins on Friday.

Rosell Herrera sparked the winning rally with a one-out double off Trevor Hildenberger (4-4), who took over as Minnesota's closer after Fernando Rodney was traded to Oakland last month. Whit Merrifield followed with an RBI single and advanced to third on Adalberto Mondesi's base hit.

Manager Paul Molitor then put in Logan Forsythe, giving the Twins five infielders, and Alex Gordon was intentionally walked to load the bases. But Perez thwarted the strategy with a drive to center for his 26th homer.

''I was sitting on a slider,'' Perez said. ''It surprised me a lot when he threw me a fastball first pitch right down the middle, but after that I was just trying to do my best to put the ball in play and see what happens.''

The Twins' loss lowered Cleveland's magic number for clinching the AL Central title to one.

''We know Perez is a Twins killer and all those kind of things, but it would have been a little bit trickier to try to find a way to do that with Gordon,'' Molitor said. ''So, we went ahead and gave it a shot and he did a good job of fouling off some tough pitches and working it to 3-2, and we had to throw a strike.''

It was Perez's second career game-ending homer and the sixth game-ending slam in Royals history. Perez said he was so focused on trying to hit the ball in the air he didn't realize there were five infielders until the third pitch.

''As soon as I hit it, I knew we were going to bring him in (with the winning run),'' Perez said. ''If it had hit the wall, I didn't care. I just wanted to win. But as soon as I saw the ball going, I got more excited.''

Last-place Kansas City improved to 12-2 in its last 14 home games after going 11-35 at Kauffman Stadium before the All-Star break.

''It's getting fun again,'' Royals manager Ned Yost said. ''For a while, it wasn't a whole lot of fun, but you just keep your head up and keep working. But it's starting to get fun again.''

Perez also had an RBI single in the first inning and Mondesi connected for his eighth homer in the seventh, a 437-foot drive into the right-field fountains. Jason Hammel (3-13) pitched a scoreless inning for the win.

Robbie Grossman and Willians Astudillo each had three hits for Minnesota, which also dropped the opener of the four-game set on Thursday.

Joe Mauer had a run-scoring double in the Twins' three-run fifth, and Astudillo made it 4-2 when he singled in Grossman in the seventh.

But Mondesi went deep in the bottom half of the inning and the Royals nearly tied it in the eighth. Ryan O'Hearn tried to score from first on Jorge Bonifacio's two-out double, but Astudillo made a diving tag to get him at the plate.

''That was a great send right there,'' Yost said. ''You hate the outcome. You don't really want him thrown out, but I'm thinking if I'm coaching at third base I'm sending him right there, too. You've got to make them make that play.''

Minnesota wasted a solid start by Jose Berrios, who struck out nine while pitching six innings of two-run ball.

Kansas City right-hander Jorge Lopez was charged with three runs and nine hits in 4 1/3 innings. He departed with a left rib contusion after a fourth-inning collision with third baseman Hunter Dozier.

''He hit me right here in the chest,'' Lopez said, lifting his shirt to reveal a bandage just below his left pectoral muscle. ''I just reacted to that ball and didn't know he was going to go that far. I should not be there.''

WORTH NOTING

Mauer's double was his 598th extra-base hit, breaking a tie with Tony Oliva for fourth place on the Twins' career list. He trails only Harmon Killebrew (728), Kirby Puckett (687) and Kent Hrbek (623).

TRAINER'S ROOM

Royals: After taking Dozier's shoulder to the ribs, Lopez said he started having difficulty breathing, especially when taking a deep breath. He will have an MRI on Saturday and will be re-evaluated by the training staff.

Twins: C Mitch Garver (head) remained sidelined for a second straight game while he awaits clearance from the training staff after taking a foul ball off the facemask, but he did hit in the cage before Friday's game. ''I think that's another step forward today,'' Molitor said. ... 3B Miguel Sano (lower left leg) was expected to work in the batting cage for a second consecutive day, but he remains out indefinitely.

UP NEXT

Royals RHP Ian Kennedy (1-8, 4.92 ERA) will make his second start since returning from the disabled list and second straight start against the Twins, who send RHP Chase De Jong (0-0, 0.00) to the mound for his second appearance since a July 30 trade with the Seattle Mariners.

---

More AP MLB: https://apnews.com/tag/MLB and https://twitter.com/AP-Sports

Copyright 2018 by AP. Any commercial use or distribution without the express written consent of AP is strictly prohibited.