The incumbent Democratic mayor of Buffalo — running as a write-in candidate — declared victory on Tuesday night as he led a nearly 20 point lead over his Democratic Party opponent.

India Walton, a socialist backed by many high-profile progressives, refused to concede to Mayor Byron Brown in the highly-publicized contest until her campaign sees “all the votes,” her spokesman Jesse Myerson told The Post via text.

Brown, 63, who lost to Walton in the June Democratic primary, claimed what would be a stunning victory in a speech to supporters from his campaign headquarters shortly after 11 p.m.

“Today’s election, it’s not just a referendum on the future of the city of Buffalo, it was a referendum on the future of our democracy,” Brown said.

“At the …