[Read the latest on the Queens district attorney race: On Friday, Melinda Katz saw her lead over Tiffany Cabán narrow to 16 votes.]

The polls had closed. Most of the votes had been tallied. Tiffany Cabán, the public defender and democratic socialist whose insurgent candidacy for Queens district attorney galvanized political observers nationwide, had declared victory.

And then, late Wednesday, a twist: A count of paper ballots that had not been totaled on primary night pushed Melinda Katz — the Queens borough president and establishment favorite — ahead, by the barely there margin of 20 votes.

The news thrust the borough, as well as the broader New York political world, into chaos. It threw a major victory for the left wing of the Democratic Party into doubt, and it inspired immediate recriminations about traditional party forces.