NEW YORK (AP) -- Aaron Judge hit his 51st home run to give the Yankees a quick lead, but New York missed a big chance to tighten the AL East race when Sonny Gray and the bullpen fell apart Thursday night in a 9-6 loss to the Tampa Bay Rays.
The Yankees stayed three games behind division-leading Boston, which fell to Houston 12-2. Each team has three games left and both are assured playoff spots -- if they wind up even, the Yankees would host the Red Sox in a tiebreaker Monday.
Brett Gardner, Greg Bird and pinch-hitter Aaron Hicks also homered for New York, which had won three in a row. Wilson Ramos homered during a seven-run burst in the fifth inning for the Rays, who had lost three straight.
Gardner and Judge hit back-to-back homers to begin the bottom of the first inning, and Bird connected in the fourth for a 4-1 edge.
But with the out-of-town scoreboard at Yankee Stadium showing Boston trailing by a lot, New York allowed its most runs in an inning this year.
Gray (10-12) gave up a pair of one-out singles, and a wild pitch and Gary Sanchez's major league-leading 16th passed ball each permitted runs to score. Ramos added a two-run homer off Gray, and Peter Bourjos hit a two-run triple and Cesar Puello had an RBI single against Jonathan Holder.
A crowd that earlier chanted "MVP! MVP!" for Judge wound up booing as the Yankees eventually ended an inning that also included a throwing error by Sanchez, a hit batter and a walk. Gray walked a season-worst five in 4 2/3 innings.
Chih-Wei Hu (1-1) pitched one inning for his first big league win.
Judge has gotten an extra-base hit in eight straight games. He has 11 total hits during that span -- seven homers and four doubles. Overall, the rookie has a career-best 11-game hitting streak.
Judge has 32 homers at home this season, tying Babe Ruth's team record.
Bird has posted an RBI and extra-base hit for six games in a row. The Yankees top the majors with 239 home runs, with 31 in the last 14 games.
Rays rookie Jake Faria made his first start since Aug. 16 after missing time because of an abdominal strain. He was pulled after the third while pitching in place of Alex Cobb, who's done for the season because of an innings limit.
Yankees: RHP Adam Warren (lower back spasm) is set to return Friday. Manager Joe Girardi said he'd like to get the reliever into a game or two before the playoffs. … Relievers Chad Green and Dellin Betances were held out of this game.
Rays: RHP Jake Odorizzi (10-8, 4.26 ERA) starts as the Rays host Baltimore in their final series of the season.
Yankees: RHP Masahiro Tanaka (12-12, 4.94) pitches vs. Toronto and RHP Joe Biagini (3-12, 5.34) on Friday afternoon at Yankee Stadium. If the Yankees reach the AL Division Series, Tanaka would line up to pitch Game 1.