KANSAS CITY, Mo. (AP) — Jose Ramirez is finding his swing and it's no surprise that's leading to Cleveland's best stretch of the season.

Ramirez hit a go-ahead homer in the 14th inning and the Indians held on to beat the Kansas City Royals 5-4 Thursday night in a game that lasted just shy of five hours and finished after midnight.

It was Ramirez's sixth home run in July, topping his combined total (five) from the first three months of the season. Cleveland is 15-4 this month, the second-best record in the majors.

"He's starting to feel good about himself. It's good, that's welcome. Those are games that you win because of that, that maybe you don't (before)," Indians manager Terry Francona said.

Ramirez also doubled twice and upped his batting average to a season-high .240. After beginning the year in an extended slump, the third baseman has heated up in July, hitting .338 this month.

Jake Bauers singled home Jason Kipnis later in the 14th off Brian Flynn (2-2) to add an insurance run — and Cleveland needed it.

A.J. Cole earned his first save since May 15, 2015, in his second major league appearance. After allowing the first three batters to reach, Cole retired the next three in order, striking out Bubba Starling to end the game.

Kansas City got a run in the 14th on Jorge Soler's sacrifice fly.

RELATED: Report: Trevor Bauer ‘less likely to be traded’ with Cleveland Indians remaining in AL Central race

"A.J. was put in a really tough spot," Francona said. "He hadn't pitched in about a week. All of a sudden, you're asking him to close out a game. He knuckled down and got them."

Francisco Lindor homered on the first pitch of the night for the Indians, who remained two games behind first-place Minnesota in the AL Central.

Nick Goody (2-0) threw two scoreless innings for the win. Cleveland's bullpen worked 8 2/3 innings, allowing just one run and four hits.

"When you can get into the 14th inning and every one of our guys out there in the bullpen is throwing up zeros, I mean, that's huge," Goody said. "That's what championship teams are made of."

Adam Plutko pitched 5 1/3 innings and gave up three runs on seven hits while making his second consecutive start against the Royals.

Lindor hit his 17th home run but Hunter Dozier answered in the bottom of the first with his 16th of the season, a two-run shot to put Kansas City up 2-1.

The Indians scored twice in the sixth to briefly take a 3-2 lead before the Royals tied it in the bottom half. Neither bullpen flinched for the next seven innings.

Josh Staumont pitched out of jams in the 11th and 12th to throw two scoreless innings in his big league debut for the Royals.

"There are very few things in life that you do for the very first time and you've put a lot of dedication, blood, sweat and tears into," Staumont said. "When it comes to fruition, even if it's just as simple as standing there for the first time, it's definitely an experience that you can't put into words."

Kevin McCarthy and Scott Barlow also tossed two scoreless innings apiece.

Starling had a career-high three hits and has a nine-game hitting streak dating to his second career game.

Mike Montgomery matched his longest outing of the season, pitching five innings and giving up one run on five hits in his second start for the Royals since coming over in a trade with the Chicago Cubs. Since July 15, Royals starters are 6-2 with a 2.45 ERA.

"I thought I made some good strides from the last one," Montgomery said. "Definitely a long way to go. Physically, I'm starting to get my legs under me a little bit better."

RELATED: Cleveland Indians: 3-year-old struck by foul ball shows no signs of serious injury