DETROIT — Jordy Mercer capped a six-run comeback with a game-winning single off Chance Adams in the ninth inning, as the Detroit Tigers overcame another onslaught by the Yankees in a 12-11 victory on Tuesday night.

Brett Gardner and Didi Gregorius each homered twice, and Gleyber Torres and Edwin Encarnación also went deep for the Yankees, whose 276 homers tied Minnesota for the major league lead.

New York (95-51) led Detroit (43-100) 6-0 in the second inning. But the Tigers tied the score with six in the third, aided by an error by the second baseman Torres, who dropped a throw from Gregorius on what appeared to be an inning-ending double play. Christin Stewart followed with a sacrifice fly, Travis Demeritte added an R.B.I. single and Grayson Greiner hit a two-run single.

Greiner doubled with one out in the ninth off Adams (1-1) and Mercer’s single to right-center scored pinch-runner Willi Castro.