BALTIMORE -- Through five innings Friday night, New York Yankees left-hander C.C. Sabathia had a no-hitter and a 3-0 lead and appeared on track for his 200th major league victory.
But four innngs later, Baltimore's Kevin Gausman was celebrating his first career win.
Nate McLouth hit a tiebreaking solo homer in the seventh inning and Gausman pitched 4 1/3 innings of scoreless relief as the Orioles rallied from a 3-0 deficit for a 4-3 win over New York.
Manny Machado added a two-run double for Baltimore, which remains in second place in the American League East, two games ahead of New York, which has lost three straight.
Gausman (1-3), whose five previous appearances have been as a starter, was considered along with T.J. McFarland for Friday's assignment. Instead, he took over for McFarland in the third inning and pitched through the seventh, allowing three hits and striking out four.
"I was thinking last night what the best relievers have, and they have that bulldog mentality, and that's something I definitely tried to come do today," said Gausman, who last pitched June 19 and knew he was in line to pitch in relief Friday.
With two outs in the seventh, McLouth (2 for 3) hit a 1-0 pitch from Sabathia (8-6) high over the scoreboard in right field.
"It was a breaking ball elevated, pretty much down the middle," McLouth said. "I'm sure he didn't want to throw it there, but I was able to put some pretty good part of the bat on it and luckily it went out."
Tommy Hunter pitched the final two innings for his second save.
Robinson Cano had three hits for the Yankees and Brett Gardner added a double and a single.
The Orioles tied the score in the sixth with the benefit of two hits that didn't go 90 feet.
McLouth got Baltimore's first hit, a line single to center leading off the inning. Alexi Castilla followed with an infield single between the mound and first. After Nick Markakis popped out, Machado lashed a double to right center, scoring McLouth and Castilla.
Machado then raced to third on a J.J. Hardy fly to center, which proved to be a key play in the game as he scored the tying run when Adam Jones hit a dribbler halfway up the first base line and beat it out for a single.
"I tell guys all the time, you feel something, you got a good feeling, go for it, and I've got the other part of it after it's over," Orioles manager Buck Showalter said of Machado risking the final out in the inning by going to third on the flyout. "But I'm going to be upset if you feel something and don't go for it."
Sabathia (8-6) went seven innings and gave up four runs and five hits. He struck out six and didn't walk a batter. He was making his 400th career start and seeking his 200th win.
"We've been battling all year, dealing with injuries and everything, and for us to come out here and put up three against a tough team and not be able to hold it late in the game is extremely frustrating," Sabathia said.
Sabathia retired the first eight Orioles before Castilla reached on an error by third baseman Alberto Gonzalez.
"His stuff was really good tonight and he was rolling along," Yankees manager Joe Girardi said.
McFarland, a 24-year-old reliever making first major league start, lasted just 2 2/3 innings, giving up three earned runs and seven hits.
New York got the leadoff man on in each of first three innings and cashed in twice, though they left five runners on in the first three innings.
Gardner hit McFarland's second pitch of the game to left center for a double and, one out later, Cano singled him home.
The Yankees opened the third with three consecutive singles, the last by Vernon Wells that scored Jayson Nix to make it 2-0. Ichiro Suzuki struck out and Zoilo Almonte grounded into a fielder's choice, but Chris Stewart lined a single to center, scoring Cano and ending McFarland's night.
"We had some opportunities and we weren't able to do it, and Gausman came in and threw the ball well," Girardi said. "You can see the kid's extremely talented."
NOTES: David Phelps was originally listed as Friday's Yankees starter and Sabathia as Saturday's pitcher. A team spokesman explained that a miscommunication between pitching coach Larry Rothschild and the PR staff resulted in the team incorrectly listing Phelps for Friday. ... Sabathia passed Jack Chesbro for 14th on the Yankees' career strikeout list with 918. ... Cano passed Frank Crosetti for 19th on the Yankees' career hit list with 1,543. ... Machado leads the majors with 37 doubles. ... INF Brian Roberts, out with a hamstring injury since early April, will rejoin Orioles on Saturday and could play Sunday.