A federal appeals court on Wednesday struck down California's requirement that masked federal agents identify themselves.
Democrats passed the “No Vigilantes Act” to rein in federal officers who were detaining people in masks and without visible identification.
But the California law was destined to face scrutiny.
An 1890 Supreme Court case specifies that a state cannot prosecute federal law enforcement officers acting in the course of their duties.
The Supremacy Clause of the Constitution also holds that states may not regulate the operations of the federal government.
California's lawyers argued that the court should have also considered the state government's concerns about federal immigration enforcement's effect on public safety.
Lawmakers this year are advancing more bills targeting the administration's immigration agents, including proposals that would bar them from employment in California law enforcement agencies and a measure that would make it easier for people to sue federal agents over civil rights violations.