In his ruling, U.S. District Court Judge Paul Barbadoro said it's speculation to think people will be coerced into selling votes if they can post the image online. During arguments in June, lawyers for the state acknowledged there are no known cases of vote-buying or coercion in New Hampshire.

State lawmakers who supported the bill said someone who wanted to coerce voters could insist on seeing pictures of their ballots to prove how they voted. With the proliferation of ways to share images - including Facebook, Twitter and Instagram - Assistant Attorney General Stephen LaBonte said the Legislature had a legitimate concern about voter fraud amid new technology.

During arguments, Barbadoro wasn't buying it.

"You think people are going to post a photo on Facebook?" he said then. "'I'm a proud seller of my vote! I just sold my vote for $25!' At some level, you have to use common sense."

Under the law that took effect in September, posting a photo of a completed ballot was a violation punishable by a fine of up to $1,000. It was supported by the state Secretary of State's office.

The American Civil Liberties Union-New Hampshire brought the case on behalf of three people who were investigated after posting ballot photos last year, including one voter who said he cast a ballot for his dead dog because he didn't like any of the candidates.

"Today's decision is a victory for the First Amendment," Gilles Bissonnette, legal director of the ACLU-NH, said in a prepared statement. "Political speech is essential to a functioning democracy. The First Amendment does not allow the state to, as it was doing here, broadly ban innocent political speech with the hope that such a sweeping ban would address underlying criminal conduct."

LaBonte said he was still reviewing the order so would not immediately comment.