The new law closed a loophole that led the state's highest court to overturn a man's conviction for sending sexually explicit instant messages to someone he believed was a 13-year-old girl.
But Internet content providers, the American Civil Liberties Union of Massachusetts and others sought to block enforcement of the law as it applies to broad-based Internet communications. They did not seek to bar enforcement against sexual predators or others who use the Internet to send harmful material to minors.
U.S. District Judge Rya Zobel ruled Tuesday that the law, as it is now written, violates the 1st Amendment.
"Our goal is to ensure that our laws keep up with modern technology in order to protect kids from sexual predators on the Internet," Attorney General Martha Coakley said.
She said her office will draft an injunction that addresses the concerns raised in the ruling and will examine if the law needs to be changed to be sure "law enforcement has the necessary tools to protect children online."
The new law was passed quickly by the state Legislature after the Supreme Judicial Court found in February that the old state law that imposes criminal penalties for disseminating material harmful to minors did not cover electronic communications.
Various free speech groups and advocates filed a federal lawsuit in July challenging the new law.
The content providers argue that the new amendments amount to "a broad censorship law" that would ban from the Internet a variety of information that could be seen as harmful to minors, including material about contraception, pregnancy, literature and art that adults have a 1st Amendment right to view.
They also argue that people who disseminate information through a generally accessible website cannot discern the ages of those who view the information and that, as a result, the law inhibits the free speech of adults.