It took 864 major league games for Jordy Mercer to hit his first game-ending homer.

DETROIT (AP) — It took 864 major league games for Jordy Mercer to hit his first game-ending homer.

As he rounded the bases Thursday, one thought went through his mind.

"All I was really thinking was how cold the Gatorade bath was going to be," he said. "I couldn't wait to get to the plate, but they really got me."

The 32-year-old Tigers shortstop didn't mind, since his two-run homer in the bottom of the ninth gave Detroit a 10-8 victory over the Kansas City Royals.

"That's an awesome feeling, especially since I had never hit one," he said. "I have a lot of game-ending hits, but you always dream about hitting a walk-off homer. This isn't the year we hoped for, but there are still good moments."

The teams combined for eight homers on a rare night where the ball was flying at Comerica Park.

"We don't get a lot of games like that here," Tigers manager Ron Gardenhire said. "It seemed like everything was going out."

Travis Demeritte led off the ninth with his third walk of the game and moved to second on a sacrifice bunt by Jake Rogers.

Mercer then hit a 2-1 fastball from Richard Lovelady (0-2) into the right-field stands for his sixth homer of the season.

"I wanted a fastball down and away and it stayed up," Lovelady said. "Every time I tried to throw a fastball away, I couldn't get it below the belt."

The homer was Detroit's fourth on a night in which both starters struggled.

Joe Jimenez (3-6) got the win with a scoreless ninth inning.

Tigers starter Matt Boyd gave up five runs on six hits, including three homers, and three walks in a season-worst 2 2/3 innings. Boyd entered the game fourth in the American League with 187 strikeouts, but only had one against the Royals.

"I knew right away I was out of sync, and that's going to happen once in a while," he said. "Usually, I can make an adjustment and get things back under control, but nothing worked tonight."

Hector Lopez, making his first start since May 25, only got four outs. He allowed five runs on two hits, three walks and a hit batter.

Against a Tigers team with the American League's worst on-base percentage, Kansas City pitchers walked nine batters.

"Walks early, walks in the middle and walks late," Royals manager Ned Yost said. "That's not good for business. We'd been better lately at containing them, but we just couldn't do it tonight."

The Royals took a 2-0 lead in the first. Whit Merrifield led off the game with a double and scored on Hunter Dozier's one-out homer to right.

Detroit, though, scored five runs on two hits in the second.

After a single and an error, Harold Castro's three-run homer gave the Tigers the lead.

Lopez walked the next two hitters and, after a groundout, hit JaCoby Jones to load the bases. He then walked Niko Goodrum on four pitches to force in Detroit's fourth run of the inning before being replaced by Kevin McCarthy.

McCarthy walked Miguel Cabrera to make it 5-2 before getting out of the inning.

Dozier led off the third with his second homer of the game, and after Jorge Soler walked, Cheslor Cuthbert hit his eighth homer over the Royals bullpen in left-center field.

Boyd retired the next two batters but walked Nick Dini, bringing Matt Hall in from the bullpen.

Kyle Zimmer replaced McCarthy to start the third and walked the first three batters he faced. Mercer struck out, but Victor Reyes bounced into a run-scoring force at second to give the Tigers a 6-5 lead.

Cabrera led off the fourth with his 473rd career homer to make it 7-5, but Gordon hit a three-run homer over the scoreboard in right-center to put the Royals ahead 8-7 in the sixth.

Demeritte hit his first major league homer to tie it in the seventh.

GORDON'S HOME AWAY FROM HOME

Gordon's sixth-inning homer was his 15th at Comerica Park, the most by any active visiting player. He is tied with Joe Crede for fifth since the stadium opened in 2000. David Ortiz is the leader with 23 in 55 games.

MEMORABLE DEBUT

Dini, making his major league debut, singled to left in the sixth inning. The catcher is the 10th Royal to play his first game in the majors in 2019.

UP NEXT

The teams play the second of four games on Friday evening, with Kansas City's Brad Keller (7-11, 3.95) facing Jackson (1-5, 11.12).