KANSAS CITY, Mo. — Brett Phillips' first career walk-off RBI came in the final game of Ned Yost's managerial career as the Royals sent out their skipper in grand fashion.

Players started pouring out of the Kansas City dugout with the throw from Minnesota Twins right fielder Ian Miller still in the air. Humberto Arteaga slid in safely, the players ran to Phillips to celebrate along the first-base line, and then each member of the team lined up to hug Yost on the field in front of the dugout.

Shortly thereafter, while Yost was setting up to do an on-field interview with Fox Sports Kansas City, veterans Alex Gordon and Salvador Perez dumped Gatorade buckets over Yost's head.

The Royals registered a 5-4 season-ending win in front of an announced 17,875 at Kauffman Stadium. The Royals finished the season with a record of 59-103.

Jorge Soler hit his 48th home run of the season in his first at-bat of the game. He crushed a 3-2 offering from Twins starting pitcher Martin Perez into the visiting bullpen behind the left-field fence.

Soler's home run left the franchise's new single-season home run record at 48, moved him past Rafael Palmeiro for the most home runs in a season by a Cuban-born player and helped him become the first player in franchise history to lead the American League in home runs.

Erick Mejia (RBI double), Nick Dini (RBI single) and Ryan O'Hearn (RBI double) also drove in runs for the Royals.

Yost substituted for both second baseman Whit Merrifield and Gordon while they were in the field. With one out in the fourth, he took Merrifield out and allowed the home crowd to give him an ovation as he came off the field. Yost did the same for Gordon with one out in the fifth. Fans cheered and applauded as Gordon made the jog in from left field, perhaps for the final time.

Gordon, 35, will decide during the offseason whether or not he'll retire. He's said throughout the season that he doesn't want to play for any other franchise.

The Royals trailed 4-3 after a Jason Castro solo home run to start the fifth inning. Castro's go-ahead smash came on a 1-1 pitch, the third homer allowed by Lopez in the game.

The Twins jumped on Lopez for two first-inning homers, including a two-run shot by C.J. Cron. Lopez finished the day having allowed four runs on six hits in six innings.

Hunter Dozier's leadoff triple in the eighth tied him with Merrifield, Adalberto Mondesi and Arizona's Eduardo Escobar for the MLB lead with 10 apiece. They became the first trio of teammates with at least 10 triples since the 1984 Houston Astros.

Dozier scored the tying run on an O'Hearn RBI double to set up the thrilling finish.