Gleyber Torres, left, and Juan Soto of the Yankees celebrate a...

Gleyber Torres, left, and Juan Soto of the Yankees celebrate a 5-4 win over the Astros on Opening Day at Minute Maid Park on Thursday in Houston. Credit: Getty Images/Tim Warner

HOUSTON — For the Yankees, the bad old days of 2023 reared their collective ugly head in the early innings of Opening Day 2024.

Nestor Cortes, never healthy last year and not particularly effective in the short amount of time he did spend on the mound, allowed four runs through two innings against a typically loaded Astros lineup on Thursday.

And a Yankees offense that all but curled up in a fetal position when faced with early crooked numbers posted by the opposition in 2023 looked familiar. They put plenty of traffic on the bases before short-circuiting, in this case hitting into three double plays in the first four innings.

Minute Maid Park, the site of more Yankees organizational heartache and heartbreak the last decade than any other ballpark, was rocking.

But the Yankees spent spring training reminding everyone that the calendar had turned for good on 2023 and that this year would be different. And on Thursday, it was.

Oswaldo Cabrera hit a tying homer in the sixth inning, Alex Verdugo lifted a go-ahead sacrifice fly in the seventh and Juan Soto threw out a runner at the plate in the bottom of the ninth to preserve that lead as the Yankees rallied for a season-opening 5-4 victory in front of a noisy sellout crowd of 42,642 that stayed engaged from the first pitch until the last and made Minute Maid sound the way it does in October.

“That was a Yankee classic right there,” Aaron Judge said, specifically talking about Soto’s busy debut as a Yankee.

But the team captain easily could have been talking about the game itself, packed throughout its 2-hour, 41-minute duration with big hits, big pitches and big defensive plays by both sides.

Soto, whose work at the plate has never been questioned but whose defense has, threw out Mauricio Dubon at the plate for the second out of the ninth after fielding Kyle Tucker’s single off Clay Holmes. The play was challenged by the Astros, who felt Jose Trevino blocked Dubon’s path to the plate, but the call stood.

“Good throw,” Trevino said after catching Soto’s one-hopper and putting the tag on Dubon, who had slid wide to the third-base side. “I thought he [Soto] had a good jump on it. I thought he came in and put a good throw in a nice area where I could catch it and put a tag on him.”

With runners at first and second, Holmes got Alex Bregman to ground sharply to Anthony Volpe to end it.

With a lineup now featuring Soto and Judge hitting 2-3, a lineup one American League scout described as “long, lean and mean,” the Yankees combined nine walks and a hit batsman with eight hits.

Still, as Aaron Boone said, “It did not look good early.”

Cortes was roughed up for three runs in the first on a two-out, two-run single by Chas McCormick and an RBI single by Yainer Diaz, and Jake Meyers’ leadoff homer in the second gave the Astros a 4-0 lead.

Cortes, however, retired 12 of the final 13 batters he faced. Meanwhile, the Yankees wore down lefthander Framber Valdez, prolific at inducing ground balls and seemingly on his game through four innings.

But not all scoreless innings are created equal. And the Yankees, despite grounding into those three double plays — including twice with the bases loaded — felt a breakthrough was inevitable.

“When you see how we went through the game, it tells you a lot,” Soto said. “We took deep at-bats in the beginning, we took good at-bats, we took good swings against him. That tells you one of those swings is going to get him.”

Or, as Boone put it of the lineup and Soto’s impact: “He embodies who we want to be on offense — wear you down, grind you out.”

Verdugo’s sacrifice fly to left in the seventh against Ryan Pressly brought in Judge, who had doubled to lead off the inning, to snap a 4-4 tie.

After Cortes held things together in his five innings, Jonathan Loaisiga, Ian Hamilton and Holmes shut out the Astros despite allowing eight of Houston’s 13 hits in four innings.

Loaisiga, among several bullpen pieces the Yankees are comfortable using for multiple innings, allowed four hits in two innings. He ended his second one by striking out Jose Abreu on a 98-mph sinker, stranding runners at first and second.

Hamilton, a bullpen stud last season before getting injured, gave up one hit in the eighth and Holmes picked up the save despite allowing three singles by the first four batters to face him.

“I remember coming in after the second inning and [pitching coach] Matt Blake telling me, ‘Hey, just hold the rope, we’re going to get some runs across,’ ” Cortes said. “We had the bases loaded a couple of times early, didn’t get anything across, but just focused on myself to give innings, to get as many outs as I can. And, obviously, the offense came [through]. It was a good one for the boys.”

More Yankees headlines

Newsday LogoSUBSCRIBEUnlimited Digital AccessOnly 25¢for 5 months
ACT NOWSALE ENDS SOON | CANCEL ANYTIME