As Masahiro Tanaka seemed to flirt with disaster throughout much of his ALCS Game 4 outing against the Astros, Chad Green warmed up multiple times in the bullpen, waiting to come to Tanaka’s — and the Yankees’ — rescue.

That was the expectation when Green entered a two-run game, but when Aaron Boone finally went to get Tanaka after Michael Brantley started the top of the sixth by reaching on an error by DJ LeMahieu at first base, Green only made the situation worse in an 8-3 loss that brought the Yankees to the brink of elimination.

After tossing 4 ²/₃ scoreless innings in his first four playoff appearances this season, Green got Yuli Gurriel to pop to short for the first out in the inning, but not before Gurriel ripped a liner down the right-field line that landed just foul.

Yordan Alvarez followed with his first hit of the series, a single to center to put runners on the corners.

Then Yankee-killer Carlos Correa landed the big blow, a three-run shot into the seats in left to give the Astros a 6-1 lead.

“It’s one bad pitch,’’ Green said. “The pitch got too much of plate and he did what he was supposed to do with it.’’

Green got out of the sixth without any further damage, but with the Yankees offense spinning its wheels, the deficit was too much to overcome.

Green hadn’t been overtaxed in the playoffs. After a long layoff following the Yankees’ sweep of the Twins in the ALDS, Green pitched two perfect innings in a Game 2 loss in Houston, throwing 26 pitches.

He needed just eight pitches to get two outs in Tuesday’s Game 3 loss in The Bronx.

But he did warm up twice before getting up again in the sixth, when he took over for Tanaka.

Green first got up with Tanaka struggling in the third, when Tanaka allowed a three-run homer to George Springer, but he didn’t think the added work in the pen had an impact on his performance.

“I don’t think so,’’ Green said. “Me and [bullpen coach Mike Harkey] have a good idea how to save pitches down there, with me potentially being up and down for a few innings.’’

Green remained confident the Yankees wouldn’t fold despite the future of their season looking bleak.

“This isn’t our first elimination game,’’ Green said. “Guys in here are used to having their backs against the wall. Don’t think it’s gonna be anything we’re not prepared for. We know what we’re up against.”