Insurgent candidate Tiffany Cabán — who has vowed to institute a slate of left-leaning criminal-justice reforms — declared victory over establishment favorite Melinda Katz Tuesday night in a tight Democratic primary race for Queens district attorney, but Katz refused to concede.

Cabán, endorsed by fellow progressives like Bronx-Queens Rep. Alexandria ­Ocasio-Cortez and Vermont Sen. Bernie Sanders, got 39.6 percent of the vote to Katz’s 38.3 percent, with 99 percent of precincts reporting.

Since Cabán’s lead stood at 1.3 percentage points, it was above the 0.5-point threshold that would make a recount mandatory.

But there were still 3,400 absentee ballots reportedly to be counted — which would likely mean Katz would have to get a large percentage of them to erase the 1,090-vote lead Cabán held over her early Wednesday.

And the Board of Elections said the tally might not be officially completed until next Wednesday.

“They said I didn’t look like a district attorney. They said I was too young. They said we could not build a movement from the grassroots. They said we could not win — but we did it, y’all,” the 31-year-old public defender told cheering supporters at La Boom nightclub in Woodside.

“We built a campaign to reduce recidivism, decriminalize poverty, end mass incarceration, and to protect our immigrant communities. To keep people rooted in their communities with the access to support and services.”

Cabán, a democratic socialist, has said that, if elected, she would not prosecute farebeaters, sex workers, johns and some recreational-drug crooks; work to close Rikers Island; and end cash bail.

Katz said a recount was warranted in the six-way race, where no candidate came close to getting 50 percent of the vote.

“We always knew this was going to be tough, because if it wasn’t tough, it wouldn’t be a race,” she said. “There’s a lot of thank-yous to be made and a lot more days until a recount, but I didn’t want tonight to go by without thanking so many of you.”

In her victory speech, Cabán acknowledged the support of Ocasio-Cortez, who tweeted about the apparent victory.

“We meet a machine with a movement,” the freshman congresswoman wrote.

Sanders congratulated Cabán in a tweet. “Tiffany Cabán took on virtually the entire political establishment and built a grassroots movement,” the Vermont socialist wrote.

“This is a victory for working people everywhere who are fighting for real political change and demanding we end cash bail, mass incarceration and the failed war on drugs.”

Cabán was joined onstage by, among others, city Comptroller Scott Stringer and Queens State Sen. Jessica Ramos.

During her campaign, Cabán also received endorsements from Sen. Elizabeth Warren and The New York Times.

The unlikely apparent victory from an insurgent candidate on the left was reminiscent of Ocasio-Cortez’s upset victory last year against nine-term incumbent US Rep. Joe Crowley in a Democratic congressional primary.

Katz received support from Gov. Cuomo and Crowley, the former Queens Democratic Party chief.

Gregory Lasak, a Queens prosecutor, took nearly 15 percent of the vote, possibly siphoning support from Katz.

Cabán ran strong in Astoria, Long Island City and Sunnyside. Katz, meanwhile, underperformed in Broad Channel and the Rockaways.

Additional reporting by Georgett Roberts