Tiffany Cabán conceded defeat Tuesday in the Democratic primary for Queens district attorney, but Melinda Katz’s victory is still a humiliation for the once-vaunted Queens machine.

After all, Katz — the borough president and a former City Council member — came this close to losing to an amateur pushing loony ideas like refusing to prosecute prostitution cases.

And an utterly unqualified one: Cabán, a career public defender, has never run a staff a tenth the size of the DA’s office, nor had to balance conflicting needs the way every prosecutor must.

But backing from Rep. Alexandria Ocasio-Cortez and the new voters behind her 2018 victory over the same Queens machine nearly did the trick.

On top of that, Katz spent much of the campaign pandering to the party’s soft-on-crime, tough-on-cops wing.

That’s unlikely to stop her from tromping her token Republican opponent in the November general election.

Indeed, Katz is all too likely to bend even further left once in office, out of fear of a primary challenge next time ’round.

Which means the real losers here are the people of Queens.