BALTIMORE — There was no carryover from one of the Yankees’ worst losses of the season.

With Aaron Judge producing early power and Sonny Gray again providing consistency on the mound, the Yankees earned their first series victory at Camden Yards since 2013 with a 9-1 win over the Orioles on Thursday. The second-place Yankees (75-64) moved within 3½ games of the idle Red Sox in the AL East.

The Yankees, wearing black armbands in honor of longtime executive Gene “Stick” Michael, who passed away Thursday morning, totaled 13 hits, including four homers.

“I’m sure he’d be happy how the game went today,” said Brett Gardner, who went 2-for-3 with two walks. “We don’t usually leave here winning a series, especially not recently, so it’s a good feeling.”

The Yankees, who had lost 11 straight series here, drove Kevin Gausman from the game after three innings and 79 pitches. Gausman (10-10, 4.99) allowed five runs, five hits and three walks.

Without Gary Sanchez, who will return from his three-game suspension Friday night in Arlington, Texas, the Yankees outscored the Orioles 22-12 in the three-game series. They could have swept it if not for Manny Machado’s walk-off two-run homer off Dellin Betances with two outs in the ninth inning Tuesday night.

advertisement | advertise on newsday

“We’ve been playing our ballgame,” said Judge, whose 39th homer tied him with Oakland’s Khris Davis for the AL lead. “Just kind of passing the baton, getting those clutch hits with runners on.”

Gray (9-9, 3.22) allowed an unearned run, six hits and two walks in 5 2⁄3 innings. He struck out five.

Judge hit a two-run home run to center in a three-run first inning and Matt Holliday and Jacoby Ellsbury drove in runs in the third to make it 5-0.

Chase Headley’s 12th homer, a two-run shot in the fourth off Mike Wright, extended the lead to 7-0. Starlin Castro’s 14th home run, off Donnie Hart in the sixth, made it 8-0. After Didi Gregorius’ two-out error produced Baltimore’s run in the sixth, Todd Frazier got it back in the seventh with his 23rd home run, off Richard Rodriguez.

The outburst was a welcome change for Gray, who had been victimized by a lack of run support in his time with the Yankees. Gray entered the day 2-4 with a 3.16 ERA for the Yankees, who totaled three runs in the four losses.

Yankees videos

“He’s done a really good job of not letting it bother him,” Joe Girardi said.

Gray was given a quick lead Thursday. Gardner led off with a walk after falling behind 0-and-2. “That’s a Stick special,” Girardi said of one of Michael’s philosophies. “Make the pitcher work.”

After Headley struck out, Gardner stole second. Castro battled for 10 pitches, striking out on a full-count, 97-mph fastball, but Gregorius pulled a 1-and-2 splitter down the first-base line for an RBI double. Then Judge teed off on a fastball up in the zone for a 3-0 lead, and Gausman wound up throwing 36 pitches in the inning.

The Yankees all but put it away in the third. Gregorius had a one-out infield hit and Judge drew his league-leading 105th walk. Holliday lined a run-scoring single to right that allowed Judge to take third, and he scored on Ellsbury’s 4-6 forceout to make it 5-0.

“It was definitely nice taking the mound with a three-run lead,” Gray said. “But what was more impressive was we didn’t just stop. We kept putting the pressure on them. And that’s something you have to do, especially when you score runs early, continue to put some more runs on the board, which we did.”