Three federal judges said the law forcing libraries to use internet filters designed to block pornography went too far.
This is because the filters could also block access to sites that contain protected speech and could violate the First Amendment.
The case highlights the conflict between the right to free speech and the desire to protect children against obscenity on the web.
Speech concerns
The Children's Internet Protection Act, passed by Congress just over a year ago, sought to prevent children from accessing pornographic material on the internet.
Public libraries would have had to install the filters by July or risk losing federal funding.
But in their 195-page ruling, the judges said it would "restrict access to a substantial amount of protected speech."
They also said they were concerned that library visitors who wanted to view sites blocked by filtering software might be embarrassed or lose their right to remain anonymous because they would have to ask permission to have the sites unblocked.
Online content
The decision is a victory for the American Library Association (ALA) and the American Civil Liberties Union.
"Filters are not the only, or the best, way to protect children," said ALA President John Berry.
"Filters provide a false sense of security that children are protected when they are not."
Groups fighting the law argue the software designed to filter out pornographic material can still let it through, while inadvertently blocking internet sites such as on breast cancer or homosexuality.
US Government lawyers maintain that the law is not intended to censor libraries.
They say the law calls for libraries to use the same care in selecting online content that they use for books and magazines.
Any appeal against the latest ruling will go directly to the US Supreme Court.