Lefties nationwide are crowing over Tiffany Cabán’s apparent victory in Tuesday’s Democratic primary for the Queens district attorney job. The question now is whether leaders who represent the solid majority of the borough’s residents can join together to beat Cabán in the general election.

This is about not just the rise of the Democratic Socialists, but also the slow death of the once-vaunted Queens Democratic machine. It started losing at least three years ago, to moderates angry at how the establishment had grown out of touch with local concerns.

Brian Barnwell beat longtime Assemblywoman Marge Markey on the issue of a homeless shelter opening in Maspeth. The next year, reformer Robert Holden ousted incumbent City Councilwoman Liz Crowley.

But the machine’s weakness attracted national progressives to move in, recruit Alexandria Ocasio-Cortez to challenge Rep. Joe Crowley — and succeed in offing the king of the machine.

Rep. Greg Meeks took over as county chairman — and opted for business as usual. But AOC’s rise allows Queens lefties to fund-raise nationwide: Cabán drew a legion of small donations from across America, plus endorsements from Sens. Liz Warren and Bernie Sanders. The New York Times, desperate to renew its lefty cred, also blessed her.

And Cabán’s win wasn’t even Meeks’ only humiliation Tuesday: Lumarie Maldonado-Cruz also beat the machine, as the ex-Bronx resident won a “once-in-a-generation” countywide Civil Court race.

Borough President Melinda Katz, on Election Night a close second to Cabán, has a tiny chance of turning out the victor once all the votes are counted next week. More likely, she’ll need to find a way to fight on in the general election, by allying with voters the machine’s been ignoring — including the county’s Republicans. The current GOP candidate for DA has no hope, and there’s already talk of replacing him with Katz.

Queens residents deserve some real alternative to Cabán, who has vowed to stop prosecutions for prostitution, pot possession and other “broken windows” crimes, and to completely stop seeking cash bail.

The borough’s future is at stake: Its non-lefty majority needs to unite, and fast.