BALTIMORE (AP) — The Baltimore Orioles couldn’t have been much more frustrated at the conclusion of their penultimate homestand of the season.

After rallying from a four-run deficit, Baltimore lost to the New York Yankees 6-5 Thursday night, the Orioles’ third straight agonizing defeat against their AL East rivals.

READ MORE: 29-Year-Old Man Dies After Being Fatally Stabbed In Baltimore Thursday

On Tuesday night, Baltimore blew a 4-1 lead. The following night, the Orioles lost by a run despite outhitting the Yankees 13-6. Then came this one, when Brendan Ryan scored the tiebreaking run in the ninth inning on a wild pitch by Jim Johnson.

After defeating New York in the opener of the four-game series Monday night, Baltimore needed to win only one of the next three to capture the season series for the first time since 1997. Instead, the Yankees emerged with a 10-9 edge in 2013.

“Obviously, at this stage losing three is not ideal,” second baseman Brian Roberts said. “We started off playing so well. It kind of looked like it was heading in a really, really good direction. Had a lead a couple of times in the last three, and then to come back tonight in such a dramatic way and lose in the ninth, we’ve got some picking up to do. I think guys definitely feel a little bit down right now. We’ll have to come out with some good energy (Friday).”

The Orioles trail New York and Cleveland in the wild-card chase and fell into a tie with idle Kansas City, 2 1/2 games behind the Tampa Bay Rays.

Baltimore beings its final road trip of the season — to Toronto, Boston and Tampa Bay — on Friday.

“We’ve just got to start rattling off some wins,” first baseman Chris Davis said. “This is definitely going to be a big road trip.”

New York led 5-1 before Nick Markakis hit a solo shot in the seventh and Danny Valencia homered with two on against David Robertson in the eighth.

But the Yankees bounced right back in the ninth with an unearned run against Johnson (3-8). Ryan, obtained in a trade with Seattle on Tuesday, led off with a single. Chris Stewart bunted, and Johnson threw wildly into center field for an error that left two on.

“The ball slipped, and that kind of started the whole inning,” Johnson said.

After another bunt put the runners at second and third, Johnson uncorked a pitch that didn’t reach the plate and bounced to the backstop.

READ MORE: Baltimore Rowing Club Receives Grant to Get More Student-Athletes of Color Involved

Mariano Rivera (6-2) got straight three outs in the bottom half and was given credit for the win by the official scorer because Robertson was ineffective in the eighth.

The start was delayed by rain for 1 hour, 18 minutes.

Mark Reynolds put the Yankees up 2-0 in the second with a drive to left after Eduardo Nunez hit a leadoff single. It was Reynolds’ fourth homer in 22 games since joining New York in mid-August.

Sixty of Reynolds’ 200 career home runs came with the Orioles, from 2011-12.

Orioles starter Wei-Yin Chen allowed eight of his first 14 batters to reach base. In the third, after Alfonso Soriano sandwiched a double between two walks, Vernon Wells delivered a two-run single.

In the bottom half, Baltimore used an RBI single by Manny Machado to close to 4-1.

Curtis Granderson, who replaced injured Brett Gardner in center field, chased Chen with his second homer in two games and New York’s 10th in the four-game series.

Markakis homered off David Huff in the bottom half. Huff was originally supposed to start the game, but manager Joe Girardi figured the left-hander would be more comfortable coming out of the bullpen. Phil Hughes started and left in the fourth.

In the Orioles eighth, Soriano made a leaping grab at the left-field wall to rob Machado of a home run and keep New York’s lead at 5-2. But with two outs, Adam Jones and Markakis singled before Valencia ripped Robertson’s first pitch over the left-field wall.

NOTES: The Orioles will be without reliever Darren O’Day during the weekend series in Toronto that begins Friday. O’Day has been dealing with soreness in his fingers and has pitched only twice this month. … Jason Hammel will start Friday night for Baltimore. He replaces Bud Norris, who has been experiencing elbow discomfort. … The Orioles honored Rivera before his final game at Camden Yards. The 43-year-old closer received a gift and a standing ovation. Rivera, meanwhile, has donated the baseball he used to record his major league-record 602nd save to the Police Athletic League for auction. … Baltimore has won a season series from New York only once since 1982.

MORE NEWS: Flash Floods In Maryland Close Some Schools, Roads; Several Rescued In High Water, MSP Responds To More Than 500 Calls

(Copyright 2013 by The Associated Press. All Rights Reserved.)