NEW YORK — A judge has rejected a challenge to a law banning New York State voters from taking photographs of their marked ballots.

Thursday’s ruling tosses a lawsuit brought by voters who wanted to distribute selfies of their ballots on social media.

Judge P. Kevin Castel wrote that “secret ballots remain critical to combating vote buying and voter intimidation.” He also agreed that allowing ballot selfies would cause delays at the polls, which could turn some people away from voting.

The plaintiffs had argued the law undermines free speech. They said taking photographs of a filled out ballot is a powerful political statement that demonstrates the importance of voting. Their lawyers say they’ll appeal.

A city Law Department spokesman touted the ruling, saying it preserves the integrity of the voting process.