To get to the World Series, after digging themselves a 3-1 hole in the ALCS, the Yankees were going to have to beat both Justin Verlander and Gerrit Cole.

They got through the first Astros ace Friday night to stave off elimination.

Verlander was only vulnerable for one inning in Game 5, but the Yankees finally pounced, scoring four runs before the veteran right-hander recorded a second out, on the way to a 4-1 win over the Astros at Yankee Stadium.

The rest of the night, Verlander was largely untouchable. He retired 20 of the final 21 batters he faced and struck out nine over seven innings of work.

“I was able to settle down,” Verlander said. “Too little, too late.”

The Astros gave Verlander a 1-0 lead before he even took the mound, but his second pitch of the night landed in the right-field seats. DJ LeMahieu jumped on a 94 mph fastball and crushed it for a home run to tie the game.

It was just the second leadoff home run Verlander had allowed in 28 career playoff starts. The other came off the bat of Coco Crisp in Game 1 of the 2012 ALDS.

Six pitches later, the Yankees had men on second and third after Aaron Judge drilled a single and Gleyber Torres lofted a double to left.

Verlander struck out Giancarlo Stanton, but Aaron Hicks came up next and delivered the monster hit the Yankees had been lacking all series. In a full count, Verlander hung an 88 mph slider and Hicks dinged it off the right-field foul pole for the 4-1 lead.

“Fastball command wasn’t very good and slider was just hanging,” Verlander said. “Just wasn’t able to execute really anything.”

Verlander settled in after that, entering cruise mode by setting down 20 of 21, a harmless fourth-inning single by Didi Gregorius being the only exception.

The long ball also hurt Verlander in his other start in Game 2 of this series. He went 6 ²/₃ innings that night, with the only two runs he allowed coming on an Aaron Judge homer.

“He was incredible after the first,” Astros manager A.J. Hinch said.

If nothing else, Verlander put the Astros in a good spot for Saturday, when they will turn to a bullpen day for Game 6. Verlander’s night had potential for disaster in the first inning, but instead, the only Astros reliever to pitch Friday night was Brad Peacock, who threw an eight-pitch eighth inning.

“Very disappointed in the first and then not so disappointed in the rest of it,” Verlander said. “I’m able to at least take away a positive from the last six innings and keeping our bullpen fresh. Hopefully that’ll help us win another ballgame.”