As election results in the Queens district attorney’s Democratic primary race began coming in Tuesday evening, it was looking quite good for Melinda Katz, the Queens borough president who had the backing of the famous Queens machine. That supporting cast included every local member of the congressional delegation (save one), as well as the most famous ex-member, the one-time king of Queens, Joe Crowley.

Crowley lost his seat in a stunner a year ago this week, and a shock was in store for Katz, too. As the votes continued to be tallied, Tiffany Cabán, running on a radical decarceration platform, surged into the lead, and supporters of Cabán erupted. She held the lead through the night and declared victory just before midnight, with 99 percent of the precincts reporting, holding on to a lead of 1,090 votes. The outstanding precincts were all in Jackson Heights, a Cabán stronghold, and there don’t appear to be enough absentee ballots outstanding to swing the election.

A local contest that typically has low voter turnout and gets little attention from national media drew endorsements from two of the leading Democratic presidential candidates, not to mention John Legend, along with shocking, if muted, backing from the New York Times editorial board— all for underdog public defender Tiffany Cabán.

Cabán’s apparent victory is a show of force in New York for the local chapter of the Democratic Socialists of America, which worked hard for Cabán early, as well as for the Working Families Party and Real Justice PAC. Larry Krasner, the Philadelphia district attorney elected with the help of Real Justice on a similarly radical platform, was in attendance at Cabán’s election night party.

The most significant endorsement, however, likely came from Bronx and Queens Rep. Alexandria Ocasio-Cortez. The district attorney has jurisdiction over all of Queens and its some 2.4 million residents, but Cabán put up huge margins in portions of Queens represented by Ocasio-Cortez, which is both a reflection of their aligned politics and the influence of Ocasio-Cortez. A year ago, the party establishment could claim — whether it was true or not — to have been caught off guard by Ocasio-Cortez. That rationale is absent in Tuesday’s race. The eyes of the country were on Queens, and the machine was as prepared as it could be. It simply couldn’t muscle out the vote.

“Take nothing for granted,” said Daeha Ko, who spent his day canvassing for Cabán in Astoria, early in the night to a fellow supporter. By the end of the night, he might have been talking to Katz.

While Cabán’s election night gathering exploded by the end of the night, Katz’s — at an Irish pub in Forest Hills — was much more muted. As the TVs turned from cheering Cabán supporters to ESPN, she left without conceding, gesturing to the absentee ballots that have yet to be counted. “Mainly they were able to get out the vote,” said Sohail Rana, a volunteer with the Katz campaign. Rana said he supports Katz because of her position on bail and her years in public office.

One of the seven candidates, New York City Councilman Rory Lancman, who led a promising campaign but dropped behind as Cabán’s campaign picked up steam, dropped out with just five days to go. After months of denouncing her for being a career politician and having no criminal courtroom experience, Lancman announced he’d be endorsing Katz. And one of the trailing candidates in the race, former D.C. Deputy Attorney General Mina Malik, told a crowd in Southeast Queens on the Thursday evening before election day that “Bernie Sanders is the reason we have Trump in the White House.”

With a few weeks to go, Katz, the favorite of the Queens Democratic machine, started sending out fliers attacking both Cabán and retired New York Supreme Court Justice Greg Lasak — a move that one strategist close to the race who declined to speak on the record described as a sign that her campaign was “running scared.” Sending out negative mail, they said, is not something a confident frontrunner would do.

But at a time when the nation is grappling with how to address the largest incarcerated population in the world, reckoning with a history of wrongful convictions that have disproportionately landed innocent black people in prison, and reimagining a rehabilitative rather than a strictly punitive justice system, the office overseeing one of New York City’s largest incarcerated populations is finally coming around to change.

Katz, who was running for her sixth elected office in New York in 25 years, had support from former congressman and former Queens County Democratic Party Chair Crowley, Gov. Andrew Cuomo, along with New York Congressional Reps. Gregory Meeks, Tom Suozzi, Carolyn Maloney, and Adriano Espaillat, and a host of local and state unions. Meeks, despite a key vote on Capitol Hill Tuesday, was at Katz’s election night party. Earlier, he slammed Sens. Bernie Sanders, I-Vt., and Elizabeth Warren, D-Mass., for endorsing Cabán without consulting leaders of the machine. The move, he said, was “arrogant” and “patronizing.”