BALTIMORE — The New York Yankees honored Gene Michael by wearing black arm bands, and then paid homage to the man nicknamed “Stick” by winning a game for him.

Aaron Judge and Chase Headley hit two-run homers, Starlin Castro and Todd Frazier added solo shots and New York beat the Baltimore Orioles 9-1 on Thursday for its first series win at Camden Yards in four years.

Michael, who played, coached, managed and served as general manager for the Yankees, died of a heart attack Thursday at age 79.

Current manager Joe Girardi, who had a tight relationship with Michael, said his friend would have loved New York’s victory.

“That’s a Stick special. That’s exactly what that is,” Girardi said. “Make pitchers work and hit home runs. We were able to do that. So that was for Stick.”

Didi Gregorius had three hits and scored twice for the Yankees, who closed within 3 1/2 games of AL East-leading Boston and fortified their grip on the top AL wild card.

Yankees leadoff hitter Brett Gardner appreciated putting on the gray New York uniform just a little bit more on this day, knowing how much Michael meant to his storied franchise.

“You see it hanging in your locker and then when you put the jersey on you take a minute to remember and appreciate,” Gardner said. “Obviously, that represents Stick today but in the past we’ve had all sorts of guys it’s represented. I’m sure he’d be happy about how the game went.”

Sonny Gray (9-9) gave up one unearned run and six hits in 5 2/3 innings. The right-hander is 3-4 since he was acquired by New York in a July 31 trade with Oakland.

After rain postponed Wednesday night’s game, the Yankees dominated the makeup from the outset. Judge connected in the first inning for a 3-0 lead, giving him 39 home runs — second-most by a rookie in major league history behind Mark McGwire’s 49 in 1987.

“There’s been a couple at-bats this series they left a couple over the middle that seemed to miss and I didn’t swing at,” Judge said. “My mindset today was to go out and be aggressive.”

New York added two runs in the third against Kevin Gausman (10-10), and Headley’s drive off Mike Wright made it 7-0 in the fourth.

By taking two out of three, the Yankees earned their first series win in Baltimore since Sept 9-13, 2013. The 11-series drought was the second-longest in franchise history, behind only a 12-series run in Oakland from 1985-91.

“We don’t usually leave here winning the series, especially recently, so it’s a good feeling,” Gardner said.

Castro homered in the sixth for an 8-0 lead, and Frazier went deep in the seventh to give every New York starter at least one hit.

After going 6-4 on their penultimate homestand, the Orioles head to Cleveland trailing Minnesota and Los Angeles for the final AL wild card.

“I still think it’s going to be there for us,” manager Buck Showalter said, “but it’s going to be hard.”

Coming off two starts in which he didn’t allow a run over 13 2/3 innings, Gausman gave up an RBI double to Gregorius in the first before Judge ripped a belt-high fastball deep into the center-field bleachers.

“I threw a lot of good pitches early on … and obviously left a pitch up to Judge,” Gausman said. “But overall just wasn’t throwing enough strikes.”

Gausman was lifted after yielding five runs in three innings. In five starts against New York this season, the right-hander is 1-2 with a 9.27 ERA.

SHOWALTER SALUTE

Showalter had a black piece of tape across the Orioles logo on his shoulder, a salute to Michael, who hired him to manage the Yankees in 1992.

“It’s a loss for everybody. He had done it all,” Showalter said.

ROSTER MOVE

Wright was recalled from Triple-A Norfolk before the game.

TRAINER’S ROOM

Yankees: RHP Adam Warren, who was placed on the 10-day disabled list Wednesday with a lower back spasm, could return this season. “It’s possible just because he’s a reliever,” Girardi said.

Orioles: SS J.J. Hardy (wrist) could be activated Friday, Showalter said.

UP NEXT

Yankees: Masahiro Tanaka (11-10, 4.54 ERA) helps New York launch a three-game series in Texas on Friday. He is 3-0 with a 2.14 ERA over his last three starts.

Orioles: Wade Miley (8-11, 4.91 ERA) takes the mound Friday night against the AL Central-leading Indians.