DETROIT — On a night when the Yankees hit six homers, they still didn’t get enough offense to beat the dreadful Tigers.

Chance Adams allowed a game-winning single to Jordy Mercer with one out in the bottom of the ninth Tuesday, sending the Yankees to an ugly 12-11 loss at Comerica Park.

Grayson Greiner’s one-out double sparked the rally and pinch-runner Willi Castro scored the winning run.

In their race for the best record in the American League, the Yankees blew an early 6-0 lead to the worst team in the majors, as just about every pitcher Aaron Boone turned to struggled.

“Any time you score that many runs, you expect to win the game,’’ said Brett Gardner, who homered twice. “Over the course of the season, you lose games like this. A loss is a loss, it doesn’t matter how it happens. Give those guys credit.”

In fairness, there’s a chance most of the pitchers used by Boone won’t be on the postseason roster — other than Adam Ottavino, who allowed an unearned run in the seventh, and Zack Britton.

Still, the Yankees wasted a strong performance by their lineup and started what should be the easy part of their schedule in shaky fashion.

After finishing their last series against the Red Sox, the Yankees have just two games remaining against teams that are above .500 — a pair of games at Tampa Bay on their final road trip.

And while that schedule figures to be conducive to the Yankees collecting more wins as they try to top the Astros for the best record in the American League, the stretch of games against a collection of also-rans might make it a challenge for them to stay sharp as the playoffs approach.

“No matter who we play this year, guys have done a great job of staying focused,’’ Boone said before the game. “There have been very few games where we didn’t put our best foot forward or were flat. Very rarely have guys gone out there and not been focused. I expect that to continue.”

But the results weren’t there Tuesday.

After jumping to the six-run advantage, Nestor Cortes Jr. and Luis Cessa gave it all back in the bottom of the third, thanks in part to an error by Gleyber Torres that turned an inning-ending double play into a bases-loaded jam.

The Tigers scored four unearned runs, with a two-run single by Greiner tying the game at 6-6 that was set up by Clint Frazier’s ill-advised, errant throw home.

Torres helped atone for his mistake in the top of the fourth with a go-ahead, two-out homer and Didi Gregorius hit his first homer of the night in the fifth to give them an 8-6 lead.

But Cessa gave up another run in the bottom of the inning and a bases-loaded sacrifice fly by Miguel Cabrera off Jonathan Loaisiga made it 8-8 in the sixth.

A two-run single by Jeimer Candelario put Detroit ahead for the first time, but it didn’t last long, as homers by Edwin Encarnacion and Gregorius made it 11-10.

But even when Boone went to the heart of the Yankees’ pen, it didn’t work, as Ottavino walked Mercer, who advanced on a passed ball by Gary Sanchez, and Harold Castro’s single scored Mercer to knot the game again.

In the ninth, Boone went to Adams, since Tommy Kahnle was unavailable because of right wrist tendinitis and Aroldis Chapman was only going to pitch in a save situation.

“When you score 11 runs, you’re supposed to win,’’ Cortes said. “They have bats just like we do. They’re a major league team. They were ready to play and they were hungry.”

And those Tigers have now beaten the Yankees three times in four games. But Boone, like Gardner, stressed it was just one loss.

“We didn’t play well tonight,’’ the manager said. “We got beat. That’s it.’’