Raul Ibanez tied it with a pinch-hit homer in the ninth inning, then had an RBI single in the 12th, helping the Yankees remain a game up on Baltimore in the AL East with one game to go by beating the Boston Red Sox 4-3 on Tuesday night.
With a second comeback spurred by Ibanez in the last 10 days, the Yankees can secure their 13th division title since 1996.
The Yankees kept missing chances on a misty night. They were 0-58 when trailing after eight innings this season before rallying in the ninth.
AL East Outlook
Baltimore and New York wrap up their respective series Wednesday, with both games starting just after 7 p.m. ET.
The Orioles need a victory Wednesday and a Yankees loss to force a one-game tiebreaker for the division title Thursday at Camden Yards.
If not, Baltimore will face either Oakland or Texas in the one-game wild card.
Curtis Granderson led off with a single off closer Andrew Bailey and Ibanez lined a shot to right field to make it 3-all.
Ibanez came up again with two outs in the 12th after Francisco Cervelli walked in his first plate appearance of the year and Granderson drew a walk from Andrew Miller (3-2).
Ibanez hit a grounder out of the reach of shortstop Jose Iglesias and Cervelli flopped into home plate. The Yankees ran out to first base to mob Ibanez, who had a tying two-run homer against Oakland in the 13th inning on Sept. 22. He was doused with a bucket of water during a postgame interview.
"We stuck together. We stayed after them, and we were able to pull it out," Ibanez said. "I was trying not to do too much, and it found a hole."
Derek Lowe (9-11) pitched two innings for the win.
While the Orioles were chasing the Yankees in the standings, Lowe's outing was delayed briefly in the 12th by another kind of bird. A member of the grounds crew, using a bucket, chased a bird that landed on the infield and was reluctant to fly off.
The Red Sox dropped to 69-92, and the loss ensured they will finish in last place in the East for the first time since 1992.
The Yankees had at least one hit in each of the first six innings before the top three in the batting order went out successively in the seventh against Junichi Tazawa.
They loaded the bases against Bailey in the ninth but Mark Melancon relieved and got Mark Teixeira to pop up to an outfield playing in and Robinson Cano to ground out.
Managing as if this were a playoff game, manager Joe Girardi used much of his well-rested bullpen. He called on Rafael Soriano for the ninth, trailing 2-1, and the closer gave up a leadoff homer to James Loney, rankling many of the 41,564 who stayed through the rain.
He also pitched the 10th, walking one batter. It was the first time this season he pitched more than 1 1/3 innings.
Jacoby Ellsbury and Dustin Pedroia were back in Boston's lineup a day after sitting out of a 10-2 loss and immediately made an impact. Ellsbury, who sat against left-hander CC Sabathia, singled and scored from first on a double to right-centre by Pedroia, playing with a broken left ring finger. Cody Ross added a sacrifice fly against David Phelps for a 2-0 lead.
Eduardo Nunez had an RBI single off Jon Lester after Granderson reached on an infield hit, advanced to second on a throwing error by third baseman Pedro Ciriaco on the play and then stole third base.
Teixeira grounded out with runners on first and second to end the fifth and was booed by the many fans who remained in their seats.
The Yankees had runners on second and third with two outs in the seventh against Rich Hill and Ichiro Suzuki came up to chants of "Ich-iro!" He hit a sharp line drive to centre field that was caught by Ellsbury.
Orioles 1, Rays 0
Chris Davis homered for the sixth straight game and the Orioles overcame a club-record 15 strikeouts by Tampa Bay pitcher James Shields to beat the Rays.
"We're not supposed to be here. So just go out and have fun and see what happens," closer Jim Johnson said after the Orioles improved to 29-9 in one-run games.
"You have to win those games," he added. "If you're able to keep it close, you just try to find a way."
Orioles rookie Miguel Gonzalez (9-4) limited the Rays to two singles over 6 1/3 innings. The right-hander walked two and struck out seven before manager Buck Showalter turned the game over to the bullpen.
Davis joined Hall of Famer Reggie Jackson as the only Baltimore players to homer in six consecutive games, connecting off Shields (15-10) in the fourth. The Orioles managed only one other hit — Nate McLouth's sixth-inning single — in Shields' 19th career complete game and third this season.
"He made one mistake, and fortunately Chris was on it," Baltimore manager Buck Showalter said.
The Rays have lost 1-0 five times since Aug. 5 — twice to the Orioles.
"I hung a changeup. He's a pretty good hitter. I think that was probably the farthest home run I've ever given up in my career," Shields said. "I sent the bat boy over and told him to tell him, 'Can you hit it any farther?' Just joking around a little bit. He said something like, 'I'm sorry. I'll go and try and hit it 480 feet next time.' I thought that was pretty funny."
The Orioles, guaranteed at least a wild-card spot, clinched their first playoff berth in 15 years late Sunday.
Should the Orioles and Yankees have the same record after Wednesday night, they will have a one-game playoff Thursday to determine the division winner.
The Rays won the opener of the three-game series Monday night to extend a late surge that kept them in contention for the second AL wild card, but they were eliminated from post-season contention when the Oakland Athletics beat Texas a few hours later to assure themselves at least a wild card.
Brian Matusz replaced Gonzalez after the starter struck out Jeff Keppinger to begin the seventh. Darren O'Day worked the eighth for the Orioles, and Johnson finished the two-hitter for his major league-leading 51st save.
Gonzalez pitched seven scoreless innings in his only previous start at Tropicana Field on Aug. 5, but was not involved in the decision in a game the Orioles won 1-0 in 10 innings. He limited the Rays to two hits and four walks in that outing and was even tougher on them this time.
Evan Longoria singled leading off the second against the right-hander. B.J. Upton drew a leadoff walk in the fourth and was stranded at second when Longoria flied out and Keppinger struck out. Chris Gimenez opened the sixth with Tampa Bay's second hit, and Gonzalez walked Ben Zobrist with two outs before fanning Longoria to end the threat.
Shields was just as impressive, retiring 11 in a row before giving up Davis' 33rd homer. The right-hander whiffed seven of the last nine batters he faced to finish with a flourish.
"I knew this was my last game and I wanted to let it all hang out. I wanted to end on a good note, end on a bang," Shields said. "That was probably the best game of my career."
Davis homered over the centre-field wall on a 1-1 changeup with two outs in the fourth. Jackson homered in six straight games for the Orioles in July 1976.
"It kind of blows my mind to even be mentioned in the same breath as Reggie, but it's more about the win than anything else," Davis said. "I'm kind of glad to be the guy that's coming through in this situation, but as long as we get the win I don't care."