The law is meant to protect consumers from attempts by telecom companies to charge extra or suppress access for some websites. The legislation is also intended to protect start-ups that could not compete with bigger websites that team with telecom companies for greater exposure to internet users.

State Senator Scott Wiener, an author of the state bill, defended the law after the Justice Department lawsuit was announced.

“In their world, no one is allowed to protect an open internet,” he said. “We’ve been down this road before: when Trump and Sessions sued California and claimed we lacked the power to protect immigrants. California fought Trump and Sessions on their immigration lawsuit — California won — and California will fight this lawsuit as well.”

The F.C.C. passed net neutrality rules in 2015 with the support of President Barack Obama. But the F.C.C. chairman under President Trump, Ajit Pai, has argued that the rules aren’t needed, saying that there aren’t enough examples of harm to justify rules on broadband providers. Some promotions, like zero rating, in which a company like Verizon may offer free streaming of Hulu but not Netflix, could be good for consumers, he said.

“The internet is free and open today, and it will continue to be under the light-touch protections,” Mr. Pai said in a statement supporting the Justice Department lawsuit.

Since the F.C.C. dismantled federal net neutrality rules last December, four states, including California, passed their own net neutrality laws. The F.C.C. has argued that the states are not allowed to create new rules. But state legislators and consumer groups have said they are prepared to fight any lawsuits.

“When the F.C.C. chose to ignore the millions of consumers who urged them not to repeal net neutrality protections last year, it left a void that state lawmakers are now rightly filling,” said Jonathan Schwantes, senior policy counsel for Consumers Union.