It was nearly 1 a.m. when the Yankees finally left their clubhouse in The Bronx, knowing they had to wait at least one more day to clinch their first AL East title since 2012.

They had their chances Wednesday night/Thursday morning, first in a 3-2 loss to the Angels and then later, when the players and coaches stayed until the bitter end of the Rays’ 8-7, 11-inning win over the Dodgers in Los Angeles.

Along the way, CC Sabathia made what could be his final start at Yankee Stadium, Giancarlo Stanton had his long-awaited return to the lineup and the night could have had a much different ending if the Dodgers didn’t blow a two-run lead in the bottom of the ninth.

Aaron Boone admitted the Yankees “got pretty close” to celebrating as they watched.

The lockers were all covered in plastic and goggles were on hand, but ultimately never used.

“We were all ready to go,’’ Boone said. “Hopefully we have better luck [Thursday].”

That’s when they will have another opportunity to win the division with a victory over the Angels — and seal it with a win.

“That’s certainly how we spin it,’’ Boone said. “I think that’s a better way to do it. I hope we do that [Thursday].”

They were forced to rely on the Dodgers because they couldn’t knock off the Angels.

Sabathia allowed two runs before leaving in the third inning with the bases loaded to a standing ovation, as he waved his hat to the fans and was greeted in front of the Yankee dugout by his teammates.

The Yankees tied the game with Aaron Judge’s two-run homer in the bottom of the third, but Adam Ottavino gave up an unearned run when he made several defensive mistakes in the sixth to let the Angels take the lead.

Stanton, who played his first game since June 25 and looked good both at the plate and in left field after being sidelined with a right knee sprain.

He doubled in his first at-bat, hit a hard groundout in his second and made a strong throw from left that nearly got David Fletcher at the plate.

After a sixth-inning strikeout, Stanton was pulled, as Boone looks to build him up in the final days of the regular season.

As for Sabathia, the 39-year-old showed flashes of excellence — especially in the second inning, when he struck out the side in order — but he struggled in the third inning and left after just 2²/₃ innings with his postseason status still uncertain.

“It was good to be out there, especially with a chance to clinch,’’ Sabathia said. “That’s all I was really think about, was trying to make good pitches. When the team’s in the position that it’s in, it kind of takes the focus off of you.’’

Sabathia allowed a bunt single to David Fletcher to lead off the game and made a diving attempt to get to the ball.

The Angels got to him in the third with RBI singles by Albert Pujols and Kevan Smith.

Sabathia got lefty-swinging Brian Goodwin to pop to second before Boone went to the mound to get Sabathia.

Sabathia embraced his manager and waved his cap as he walked to the dugout, where he was greeted by the entire team.

Sabathia gave up five hits, two earned runs and struck out four.

He could still end up on the playoff roster, perhaps in tandem with Domingo German, who took over for Sabathia for a second straight outing. He left the bases loaded by getting Taylor Ward to ground out.

Sabathia said he’s “ready to do whatever they ask.”

And if that means pitching out of the bullpen, he’d like to do it before the playoffs start.

None of that has been determined yet, according to Boone.