The law made it a felony for people to encourage an immigrant to enter or live in the U.S. if they know the person would be doing so illegally.
The law violates the First Amendment because it criminalizes a substantial amount of protected speech, a three-judge panel of the 9th U.S. Circuit Court of Appeals said.
The statute, for example, would make it illegal for a grandmother to urge her grandson to ignore limits on his visa by encouraging him to stay in the U.S., Judge A. Wallace Tashima said.
In addition, a speech addressed to a crowd that encouraged everyone in the country illegally to stay here could also lead to a criminal prosecution, Tashima said.
"Criminalizing expression like this threatens almost anyone willing to weigh in on the debate," he said.
A message to the Justice Department was not immediately returned.
Attorneys for the government argued that the law only prohibited conduct and a very narrow band of speech that was not protected by the U.S. Constitution. They also said it had not been used against "efforts to persuade, expressions of moral support, or abstract advocacy regarding immigration."
The law preceded the Trump administration, but it posed a greater threat now given the administration's hard line on immigration, said Kari Hong, who teaches immigration law at Boston College Law School.
Hong co-authored a brief in the case that encouraged the 9th Circuit to apply the law narrowly. She said in a phone interview on Tuesday that the law was a danger to attorneys advising immigrants about how to obtain legal residency and public officials who promote so-called sanctuary policies that limit cooperation with federal immigration authorities.
"What this decision does is make clear that statements of encouragement that immigrants are welcome will not be subject to criminal prosecution," she said.
The ruling came in the case of an immigration consultant in San Jose, Evelyn Sineneng-Smith, who was convicted of fraud after prosecutors said she falsely told immigrants they could obtain permanent residency under a program she knew had expired.
Sineneng-Smith was also convicted of two counts of encouraging or inducing an immigrant to remain in the country for financial gain. Sineneng-Smith appealed those convictions as unconstitutional, and the 9th Circuit panel in Tuesday's ruling overturned them.
Copyright 2019 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.