NEW YORK — Kevin Gausman and the Baltimore Orioles quickly put two blowout losses at Yankee Stadium in the past.

A good pitching performance can do that, every time.

Gausman tamed the torrid New York hitters, Mark Trumbo lined his major league-leading 40th home run and Steve Pearce also connected as Baltimore averted a bruising sweep with a 5-0 win Sunday.

The Orioles had been getting battered by the Yankees this weekend, outscored 27-9.

"Obviously, the first two games didn't go the way we wanted," Gausman said.

Baltimore bounced back in the matchup between AL East playoff contenders, halting its three-game skid and ending the Yankees' win string at four.

Gausman (6-10) threw seven innings, giving up seven hits. He struck out nine and walked none to win his third start in a row.

"I was just trying to go out there and be a stopper today," he said.

Gausman posted a rare road victory after going 0-16 in his previous 25 starts away from Camden Yards. He'd thrown well several times, but had nothing to show for it.

"I'm pretty relieved. It's been kind of annoying here," he said.

Gausman, newly signed Tommy Hunter and closer Zach Britton handed New York its first home shutout in more than a year.

Yankees rookie sensation Gary Sanchez doubled and singled. He had homered in three straight games and is hitting .405 in 22 games this year.

"If someone says you're going to win a series against Baltimore, I think you're going to be pretty positive," Yankees manager Joe Girardi said. "But when you win the first two, sometimes guys can get down a little bit."

Gausman's last pitch resulted in a grounder that third baseman Manny Machado backhanded and threw from his knees from foul ground across the diamond for the out. This was Gausman's fourth fine start against the Yankees this season and he finally wound up with a win, permitting only three earned runs in 27 2/3 innings during that span.

CC Sabathia (8-11) shut out the Orioles on two singles until Pearce led off the sixth with his 12th home run.

Earlier in the game, Pearce had been having fun with the fans in right field, tossing them balls after warmups between innings — he provided another souvenir with his drive to deep left.

Like the rest of the Orioles, he didn't dwell on the previous two losses.

"We flushed them. We weren't looking back," he said.

Pearce greeted reliever Adam Warren with a two-out, bases-loaded single in the seventh for a 3-0 lead.

Batting leadoff for the first time in his 10-season career, Pearce had three hits. He also made a strong throw from right field to cut down Sanchez trying to reach third.

Trumbo connected in the eighth for a two-run shot off Ben Heller. The slugger reached 40 home runs for the first time in his career and boosted Baltimore's homer total to 204, most in the majors.

"It's hard to have a goal like that going into the season," Trumbo said. "It's such a lofty number."

Hunter, cut by Cleveland on Thursday, officially signed with the Orioles before the game and worked the eighth. He pitched parts of the last five seasons with Baltimore.

"It felt pretty good," Hunter said. "Familiar faces."

HIT THE MARK

Trumbo got to 40 homers in his 129th game, making him the fifth-fastest Orioles player to get there. Chris Davis (109 in 2013), Jim Gentile (119 in 1961), Brady Anderson (120 in 1996) and Frank Robinson (123 in 1966) were faster.

TRAINER'S ROOM

Orioles: CF Adam Jones (hamstring) hasn't played since an early exit Friday night. "We'll see what tomorrow brings. He's getting there," manager Buck Showalter said. ... RHP Chris Tillman (right shoulder bursitis) is progressing well and his throwing session was moved up a day to Monday. He can come off the disabled list Sept. 5, but Showalter said it would likely be a few days after that.

Yankees: 3B Chase Headley didn't start for the second straight day. He's feeling fine, Girardi said, but Ronald Torreyes is playing well and getting extra time. Torreyes doubled and singled.

UP NEXT

Orioles: Open a three-game series at home vs. division-leading Toronto on Monday night. LHP Wade Miley (8-10, 5.51 ERA) is 1-2 with an 8.18 ERA in five starts since the Orioles got him from Seattle at the trade deadline. RHP Marco Estrada (7-6, 3.47) pitches for the Blue Jays.

Yankees: RHP Michael Pineda (6-10, 5.02) starts the opener of a three-game series at Kansas City on six days' rest. RHP Dillon Gee (5-7, 4.55) pitches for the Royals.