NEW YORK -- Wilson Ramos' go-ahead two-run homer as part of a seven-run fifth inning helped the Rays rally for a 9-6 victory Thursday night at Yankee Stadium, averting a series sweep while all but nixing the Yankees' hopes of securing the American League East title.
Despite Aaron Judge's American League-leading 51st home run, the Yankees' elimination number in the division was reduced to one, meaning the next the next Red Sox win or Yankees loss will hand the AL East to Boston. The Yanks would then play the Twins in the AL Wild Card Game on Tuesday in New York.
"It's frustrating, because we had a chance to pick up a game," Yankees manager Joe Girardi said. "Now it's three [back] with three to go. There's still a lot of things that can happen, but it's frustrating."
The Yankees will have an opportunity to put the loss behind them quickly, because they open their final series of the season on Friday at 1:10 p.m. ET vs. the Blue Jays.
Brett Gardner and Judge hit back-to-back homers off Tampa Bay starter Jake Faria to open the bottom of the first. Greg Bird greeted Chih-Wei Hu with a fourth-inning blast as the Yankees built an early 4-1 lead behind Sonny Gray, who held the Rays to a Corey Dickerson's career-high 26th homer through the first four innings.
Gray unraveled in the fifth, uncorking a run-scoring wild pitch, and Gary Sanchez committed his Major League-leading 16th passed ball ahead of Ramos' two-run homer.
"That was a good day today," said Ramos, who was robbed of a grand slam by Aaron Hicks in Tuesday's game. "I got a little bit scared with [center-fielder Jacoby Ellsbury] stopped and jumped. But finally, I get that one."
The seven-run inning equaled the Rays' season high, also done May 14 against Boston.
"That was a pretty impressive inning on our part," Rays manager Kevin Cash said. "I think we batted around, so a lot of people played a huge role. I thought the bullpen came in and did a nice job. We got big hits from a lot of people."
Gray was charged with six earned runs in 4 2/3 innings, absorbing his seventh loss in 11 starts since being acquired by New York.
• Gray has Girardi's support heading to playoffs
"Obviously, I didn't throw that many strikes," Gray said. "Anytime you walk five guys, you're fighting yourself a little bit and it all seemed to catch up with me in the fifth."
Hicks hit a pinch-hit, ninth-inning homer for the Yankees, who lost for just the second time in 13 home games.
MOMENTS THAT MATTERED
Opening the door: It was a rough night for Sanchez, who was hit in the neck by a bounced curveball and drilled behind the left shoulder while batting. The most costly sequence came in the fifth, as Gray uncorked a wild pitch that allowed Mallex Smith to score Tampa Bay's second run, with Dickerson advancing to third base on Sanchez's throwing error. With Lucas Duda batting, Sanchez was then charged with a passed ball that let Dickerson score.
"I think he's played pretty well. There were a lot of balls he had to block tonight," Girardi said. "And there were a couple that got by him, and that's going to happen. I feel good about his defense. I feel good about the progress he has made. Will he get better as time goes on? Absolutely. But I think he's made a lot of progress."
Just the one: The Yankees threatened to strike back in the bottom of the fifth against Tommy Hunter, as Gardner worked a leadoff walk and Sanchez was hit by a pitch with one out. After a fielder's choice, Starlin Castro legged out a run-scoring infield single, but Hunter recovered to fan Bird on a foul tip.
"That was fun. That was very exciting for our team. We never hung our heads down. Just keep your head up. Keep working. Have good at-bats. And that's how we win games." -- Ramos, on the seven-run fifth
SOUND SMART WITH YOUR FRIENDS
Judge is just the third player in Major League history age 25 or younger to compile 125 runs scored and 125 walks in a season. Judge joined some select company: Babe Ruth did it in 1920, while Ted Williams did it in 1941 and '42.
IT'S NOT HOW YOU START...
The Rays have allowed back-to-back homers to start the game three times this season. Joining Faria in the troika are Chris Archer (Sept. 2 at White Sox) and Alex Cobb (May 23 vs. the Angels).
Rays:Jake Odorizzi (10-8, 4.26) gets the nod as the Rays open their final series Friday in a 7:10 p.m. ET contest against the Orioles at Tropicana Field. He has gone 3-1 with a 1.21 ERA in four starts this month, compared to 2-4 with a 6.45 ERA in his previous eight starts from July 7-Aug. 30.
Yankees:Masahiro Tanaka (12-12, 4.94 ERA) will attempt to finish his regular season on a strong note as the Yankees open a three-game series with the Blue Jays on Friday at 1:05 p.m. ET at Yankee Stadium. Right-hander Joe Biagini (3-12, 5.34) starts for Toronto.
Watch every out-of-market regular-season game live on MLB.TV.