Travis d’Arnaud hit three home runs, including a startling three-run shot with two outs in the ninth inning off Aroldis Chapman, and the visiting Tampa Bay Rays came back to beat the Yankees, 5-4, on Monday night.

D’Arnaud went the other way on a full-count breaking ball, lofting a go-ahead drive that sailed over the leaping right fielder Aaron Judge. Several Rays players spilled from the dugout to congratulate d’Arnaud while the announced crowd of 43,173 fell silent.

D’Arnaud, a catcher who began his career with the Mets, tied a Tampa Bay record for homers in a game. It had previously been done four times, most recently by Evan Longoria in 2012.

The Yankees had been 49-0 this season when leading after eight innings. The Rays won for just the second time in seven games in the Bronx this year and cut the Yankees’ lead in the A.L. East to five games.