KANSAS CITY, Mo. — The Yankees appeared to be in sell-off mode at the non-waiver trading deadline, sending away starter Ivan Nova and top relievers Aroldis Chapman and Andrew Miller in what looked like a nod to the future.

Turns out the future may have been a month away.

The Yankees beat the Kansas City Royals 5-4 in 13 innings Wednesday night, their second straight extra-inning win against the reigning World Series champs. It capped a strong August for the Yankees that left them just 2 1/2 games out of the second AL wild-card spot.

“We went through the trade deadline and I still felt we could win in here and these guys are showing it,” Yankees manager Joe Girardi said. “There’s a toughness in there and these guys really want it.”

Royals reliever Chris Young (3-9) gave up a single to Didi Gregorius and a double to Starlin Castro to lead off the decisive 13th inning. Matt Strahm came in against Brian McCann for a lefty-lefty matchup, and the New York designated hitter lofted a fly ball to left to score the go-ahead run.

Ben Heller (1-0) pitched a perfect 12th to earn his first major league victory, which Dellin Betances preserved by working around a leadoff walk for his seventh save.

“Everybody was calm under pressure,” said Yankees reliever Adam Warren, who contributed to seven shutout innings from the bullpen. “It was kind of neat to see Ben get his first win.”

Castro hit a two-run homer for the Yankees. Kendrys Morales hit one for Kansas City.

The Royals appeared to have quickly erased the memories of their rain-delayed, 5-4 loss in 10 innings the previous night when Morales homered for the second straight game with two outs in the first.

Kansas City added another run off Luis Cessa in the second on an error by third baseman Chase Headley and a timely double by Alcides Escobar, then made it 4-0 when Eric Hosmer homered to left in the third.

Ian Kennedy was cruising along for Kansas City until the sixth, when Gregorius lofted a sacrifice fly to left field. Castro followed moments later with his two-run shot.

Kennedy’s night was done when he walked Aaron Hicks with one out in the sixth. Scott Alexander came in and gave up a single to Brett Gardner and Jacoby Ellsbury’s tying sacrifice fly to center.

Both teams had chances to push runs across before the 13th inning.

The Royals’ Raul Mondesi drew a leadoff walk in the seventh and Jarrod Dyson dropped a sacrifice bunt to get him to second base with only one out. But Mondesi got caught straying between second and third, and Cheslor Cuthbert promptly struck out to end the inning.

In the 11th, Salvador Perez walked and pinch-runner Billy Burns stole his way to third. He wound up stranded there when Paulo Orlando ripped a line drive right at Castro at second base.

The Yankees loaded the bases with one out in the 12th, but Gary Sanchez lined out to Cuthbert at third base and Mark Teixeira chopped a grounder to shortstop to end that threat.

“The off day is going to do us good tomorrow,” Royals manager Ned Yost said. “Everybody is going to be able to recharge a little bit. It’s going to be good for us to just relax a little bit.”

YANKEES DEAL

The Yankees sent OF Ben Gamel, the MVP of the International League, to Seattle for minor league RHPs Jio Orozco and Juan De Paula on Wednesday. They also sent cash to Milwaukee for speedy OF Eric Young Jr., who Girardi said could join the club when rosters expand later this week.

ROYALS MOVES

RHP Chien-Ming Wang was placed on the DL with biceps tendinitis after tossing two scoreless innings on Tuesday night. The Royals shored up their taxed bullpen by recalling Alexander and RHP Brooks Pounders from Triple-A Omaha and optioning INF Christian Colon to the same club.

TRAINER’S ROOM

Yankees: Hicks left the game after grounding out in the ninth, limping his way to the dugout with a right hamstring strain. “I’m concerned,” Girardi said. “It’s probably not a day-to-day thing.”

Royals: CF Lorenzo Cain (sprained wrist) got the night off. He’s been playing in pain for about two weeks. “It’s been pretty sore,” Yost said. “It’s not a thing that’s going to heal in a week.”

UP NEXT

The Yankees take Thursday off before sending RHP Chad Green to the mound to start a three-game set in Baltimore on Friday night. LHP Danny Duffy gets the call for the Royals when Detroit visits Friday night to open their three-game series at Kauffman Stadium.