Starlin Castro tips his cap to the Cubs dugout before batting in the first inning Friday, his first game back at Wrigley Field since being traded from the Cubs to the Yankees before the 2016 season.Getty Images

CHICAGO — For the loyal denizens of Wrigley Field, it must have felt Friday like Starlin Castro never left.

Same walk-up song.

Same hit tool.

Same propensity for head-scratching plays.

Cubs fans were one strike away from chuckling over the return of Castro in a Yankees uniform. Instead, when Brett Gardner’s two-out, three-run, ninth-inning homer off Hector Rondon gave the surging Yankees a dramatic 3-2 victory, Castro stood on the right side of a result that dominated his time here: a Cubs loss.

“It was a really emotional game to come back here and play against a team that gave me my first opportunity to be a ballplayer,” Castro said.

The 27-year-old, whom the Cubs traded to the Yankees in December 2015, contributed a pair of singles in four at-bats, raising his 2017 slash line to a spectacular .367/.405/.541. He received a standing ovation when he came to bat for the first time, in the top of the first — to his old walk-up song, “Ando En La Versace” by Omega — and the Cubs showed a Castro highlight video before the second inning.

“I’m really happy for him,” Cubs manager Joe Maddon said of Castro. “I really expect or anticipate that he’s going to continue to become better offensively and defensively.”

Alas, everyone knows what has held back the obviously talented Castro are inconsistency and, intertwined with that, a tendency to commit mental errors. He contributed one of those Friday, too.

After reaching base on an infield single with one out in the sixth, Castro advanced to third on base hits by Aaron Judge and Didi Gregorius. Chase Headley hit a line drive to medium right field that, off the bat, looked like a good bet to score Castro from third on a very windy day. But Castro lingered too far off the bag and tagged up late after Jason Heyward caught the ball. As Heyward threw the ball up the third-base line, forcing Cubs catcher Willson Contreras to move away from the plate, Castro collided with Contreras, knocking him down and also getting tagged out for the inning-ending double play.

“I hit him good. I hit him hard,” Castro said. “I tried to go away from him, but he was going the same way I was going.”