HOUSTON – Leaving here with a series win – by any means possible – was the Yankees’ aim, and they accomplished that task against the AL West-leading Astros.

“Definitely eventful,’’ said Yanks starter Carlos Rodon. “A lot of stuff going on.’’

But once closer David Bednar escaped his own ninth-inning drama and secured Thursday night’s 8-4 victory, all the three-game, three-ring circus-y stuff was past tense.

Now, the Yankees (78-62) have their full focus on the Toronto Blue Jays, with a chance to make a dent in their three-game AL East lead beginning with Friday night’s series opener in the Bronx.

“Obviously, they’re a really good club and we’re excited to get after it with them,’’ manager Aaron Boone said of Toronto, winners of six of their last seven games against the Yanks.

What counted most Thursday at Daikin Park was Fernando Cruz’s huge strikeout of Jose Altuve to preserve a one-run lead in the seventh, and Trent Grisham’s latest clutch homer – a three-run shot in the eighth – which was also his 100th career blast.

What will linger, though, are familiar Yankee concerns about spotty defense (they made three more errors Thursday, with a fourth reversed by replay), guys playing out of position and relievers moving beyond the Circle of Trust.

Yankees-Astros crazy finish Thursday night

At least Bednar, on to protect a five-run lead, recovered after yielding a run and loading the bases in the ninth.

Batting as the tying runs, both Carlos Correa and Christian Walker were struck out by Bednar to end it.

Of course, Bednar – who hadn’t pitched in five days – had to wait around another seven minutes while a bat controversy played out.

Ex-Yankee Taylor Trammell’s bat was the subject of scrutiny after his ninth inning double, when Boone alerted umpires to a large sanded-looking spot on his bat.

After a while, the bat was confiscated but Trammell remained on second base, leaving a mystery as to the legality of that piece of lumber.

That was just the last of a series of conferences for an umpiring crew besieged by strange occurrences and controversial calls.

As the Yanks’ relief corps unraveled late Wednesday, an 8-7 Astros’ comeback win, Boone and reliever Devin Williams were ejected, with Boone in a hot-tempered fury at plate ump Brian Walsh.

Yankees’ survive-and-advance mode at Houston

Thursday night’s third base umpire, Walsh ruled against the Yankees on a sixth inning play where surehanded third baseman Ryan McMahon appeared to snare a low liner by Altuve.

In transferring the ball to his throwing hand, McMahon lost his grip and Walsh called it a no-catch – which led to an unearned run.

McMahon blamed himself, saying “I’ve just got to make sure to squeeze it’’ before looking to double off the runner at second base, “but I do think I caught it.’’

The play is not reviewable under MLB’s replay rules, but Boone managed to hold it together while pleading his case in vain.

“I don’t know. We overcame it,’’ said Boone, with help from starter Carlos Rodon.

“It was my turn to bail (my defense) out, and glad to do it,’’ said Rodon, charged with one run over six innings as the Yanks won a game he started for the sixth straight time.

For a second consecutive night, the Yanks’ bullpen flirted with detonating a three-run lead.

In a key moment, Cruz got Altuve swinging through a filthy 3-and-2 splitter with runners at first and second, ending the seventh and preserving a 4-3 lead.

“I’m all about passion,” said Cruz, fired up by the huge strikeout. “We needed to win a series at this place.” 

“Really gritty” Yankees win at a critical time

Out of the No. 9 spot, McMahon drove in three runs on three hits, including a solo homer, and the Yanks overcame Yordan Alvarez’s second straight four-hit night and losing Jazz Chisholm Jr. (day-to-day) with knee bruises.

Aaron Judge walked three times Thursday, as the Yanks won two of three games here without an RBI by their slugging MVP captain.

“This took some months and some years off me, for sure,’’ Boone said with a weary smile after splitting the season series 3-3 with Houston.

“Really gritty, good performance by the guys, especially as (the Astros) started to come back, and how emotional (Wednesday) night was (in a) really tough loss.’’