NEW YORK — Starlin Castro was at the plate in the bottom of the seventh inning Thursday night when Baltimore finished a 4-0 win at Toronto, eliminating the Yankees from postseason contention.

Knowing New York had failed to reach the playoffs for the third time in four years, the mind of Yankees Manager Joe Girardi immediately shifted attention to 2017. He removed CC Sabathia after one more batter and pinch ran for Brett Gardner in the eighth when Girardi didn’t like the way the speedy outfielder was running.

“It’s kind of how I’m wired, and you start thinking about, OK, what do we need to do?” Girardi said.

Sabathia (9-12) allowed one run and four hits over a season-high 71/3 innings for his first win in a month and finished with a 3.91 ERA, his lowest since 2012. Playing his final game at Yankee Stadium, Boston’s David Ortiz was honored in a pregame ceremony, struck out, walked and ended the series 0 for 10 with four strikeouts.

But the Yankees’ thoughts were on another subpar season. They have not won a postseason game since Derek Jeter broke an ankle in the 2012 AL Championship Series opener.

After a 9-17 start, the Yankees did not get back above .500 until June 10. They were 53-53 when they brought up rookie catcher Gary Sanchez on Aug. 3 following the trades of Aroldis Chapman, Andrew Miller, Carlos Beltran and Ivan Nova.

Advertisement

Most Yankees fans looked to the future.

“Everybody gave up on us,” shortstop Didi Gregorius said. “I think we scared everybody, actually, to be honest, because nobody expected us to be all the way here.”

Aaron Judge and Tyler Austin were promoted 10 days later on the morning Alex Rodriguez was released, and they homered back to back in their first big league at-bats. The Baby Bombers began to climb the standings, pulling within one game of a wild-card spot on Sept. 10.

But even with Sanchez hitting 20 home runs in his first 51 big league games, they faded from contention with a 3-11 skid that included a four-game sweep at Fenway Park.

New York (83-76) trails Baltimore and Toronto by four games for the AL’s wild cards with three games to play. A final three-game series against the Orioles won’t have much significance for the Yankees.

“It’s pretty quiet in there, probably the quietest I’ve ever seen after a win,” Girardi said. “There were some good things that happened, but in the end we fell short and we didn’t have a successful season.”

Advertisement

Sabathia, who struggled to reinvent himself at age 36, left to a loud ovation, ending a six-start winless streak and improving to 2-2 despite a 2.37 ERA in his final eight starts. He compensated for a drop in fastball velocity by developing a cutter this season and pitched with better location using a brace on his surgically repaired right knee.

“That cutter is a game-changer for him,” catcher Brian McCann said. “When you’re changing identities and who you’ve always been as a pitcher and to have the success he had was great.”

Coming back from a 2015 season that ended with a trip to an alcohol rehabilitation center, Sabathia made 30 starts and stayed healthy except for a short disabled list stint caused by a groin strain. His $25 million option for 2017 becomes guaranteed if he is not on the DL Sunday because of a left shoulder injury.

“The way I was able to pitch and use all my pitches and make this new style work for me is definitely encouraging,” Sabathia said. “We used it a lot, had some weak contact, a lot of double plays.”

Playing against his former team, Jacoby Ellsbury hit an RBI double in the fifth off Henry Owens (0-2) for a 2-1 lead. The Yankees padded the margin in the sixth on a blustery night when Robby Scott walked Austin with the bases loaded, then threw a wild pitch that scored Chase Headley. Aaron Hicks added an RBI double in the eighth.

Xander Bogaerts hit his 21st homer for Boston (92-67), which is competing with Cleveland (91-67) and Texas (94-65) for the AL’s best record and home-field advantage throughout the postseason. A day after clinching the AL East, the Red Sox rested second baseman Dustin Pedroia, first baseman Hanley Ramirez, right fielder Mookie Betts, catcher Sandy Leon and third baseman Brock Holt from their starting lineup.

New York hopes its young players can spark a rebound similar to Boston’s.

“Coming into spring training next year, we’re expecting to win. We’re not expecting to rebuild,” McCann said. “These guys are going to play big roles and they’re ready for it.”