NEW YORK — For much of this season, the Orioles have tried to find a way to deal with things that seemed beyond their control.

Injuries happened. Then more. And, while they waited for their everyday players to return, the Orioles, with their thinning depth, played below-.500 baseball as they struggled with runners in scoring position and, at times, their pitching.

But this, a game at Yankee Stadium on Tuesday with as close to a full-strength lineup as they’ll get this late in the season, was something they could control. A win wouldn’t be enough to get them into the postseason, but it would get them one step closer.

So they did just that, beating New York 5-3. Starter Dean Kremer allowed just one run — a solo Aaron Judge homer — in five innings, while the offense not only produced with runners on base but also added home runs from Anthony Santander, Ramón Urías and Colton Cowser. The bullpen gave up two runs, but a good old 9-2-6-2-5-2-6 rundown in the seventh helped Baltimore escape what could have been a deadly, game-changing inning.

The Baltimore Banner thanks its sponsors. Become one.

They couldn’t celebrate right away. To clinch, Baltimore needed the Royals or Twins to lose.

The players tried not to scoreboard watch — Kremer didn’t even know the Orioles could clinch — but some inevitably took peeks. The Royals and Nationals went to extra innings, and the Royals won 1-0, the game finishing a few minutes before the Orioles’ did. One potential clinching scenario was out the window.

About halfway across the country, the Marlins, with Kyle Stowers and Connor Norby, whom the Orioles dealt at the deadline then surely missed down the stretch when they needed injury replacements, were in the top of the ninth in Minneapolis.

Their victory secured, the Orioles stood around waiting, crossing their fingers for the result. When it came, with Miami beating the Twins 4-1, they popped champagne.

It wasn’t a perfect season, and the Orioles played below their expectations for most of the second half, but they are in. They are guaranteed at least the third wild card spot but can claim the top wild card seed — which would give them home-field advantage in the best-of-three series — as early as Thursday.

The Baltimore Banner thanks its sponsors. Become one.

“It’s been a really tough stretch the past couple of months,” Cowser said. “To be where we’re at with the number of injures we had, I’m just really proud of this group.”

Three years ago, the Orioles suffered their third 100-loss season in a four-year span. Now they are heading to the postseason in back-to-back seasons for the first time since since 1996-97.

“When you look at the history we’ve been through the past few years, winning is difficult,” center fielder Cedric Mullins said. “Every single game, day in and day out, 162, to get to this position is not easy. … Obviously, the end goal is obviously to get to the World Series, but these wins have to be celebrated.”

Last year, the Orioles won the American League East as almost everything went right. This year hasn’t been as smooth. The Orioles have had a deluge of injures, but the past week has seen the return of key contributors in Urías, Ryan Mountcastle, Jordan Westburg, Danny Coulombe and Jacob Webb, as well as promising young outfielder Heston Kjerstad. Suddenly, those problems that plagued them for most of the second half aren’t as big a concern as they’ve won three of their last five.

“We were always a good team — it was just a matter of getting going again, just going through that lull for a while there,” shortstop Gunnar Henderson said. “But it seems like we’re starting to click at the right time. The bats are starting to get going, and the pitching is really holding us down.”

The Baltimore Banner thanks its sponsors. Become one.

Now, the regular season can be wiped clean. Everyone starts fresh in the postseason, and the Orioles will have a chance to put their second-half struggles — in addition to last year’s disappointing playoff run — behind them. The wild card series will begin on Oct. 1, and they are currently slated to host either the Royals or the Tigers.

“It feels really good,” Kremer said. “I think that this is going to be a fresh start. We don’t have to grind now; we’re in. I think it’s a breath of fresh air for a lot of guys.”