A Superior Court judge has tossed out a San Francisco city ordinance that made it illegal to evict teachers and child care providers during the school year, a law city officials hoped would help stem the exodus of educators being priced out of the city.

In the decision filed Wednesday, Judge Ronald Quidachay stated that the law, which the Board of Supervisors passed unanimously this year, is “invalid on its face, pre-empted by state law and unenforceable.”

The judge’s order blocks the city from enforcing the ordinance.

The legislation, authored by Supervisor David Campos, prohibited most no-fault evictions during the academic year against employees at San Francisco public, private and parochial schools and child care centers. While the ruling is a blow to both teachers and to tenant-friendly lawmakers, it was not unexpected, Campos said.

“Every time we do something like this to protect tenants, we expect pushback from the other side,” Campos said. “They are going to challenge everything we do. We take a long view. You have a set of laws and systems that are not designed to deal with the housing crisis we are facing.”

The ordinance was challenged by the San Francisco Apartment Association, which represents the owners of rental properties, and the Small Property Owners of San Francisco Institute in a lawsuit filed June 10.

“We are pleased with the order,” said attorney Andrew Zacks, who represented the real estate groups. “The ordinance, which placed the burden on the backs of small property owners in San Francisco, was not the solution to a hard problem of housing teachers. We need to build more housing and build housing that teachers can afford to live in and do that collectively as a city.”

Currently, families with children under 18 are protected from owner move-in evictions during the school year under legislation by Supervisor Eric Mar in 2010. The Campos legislation expanded those protections to cover nearly any school employee or child care provider and any type of no-fault eviction except Ellis Act evictions, in which the landlord takes the property off the rental market altogether.

Andrea Guzman, a spokeswoman for City Attorney Dennis Herrera, said: “While we are disappointed with the ruling, we will review the judge’s order and discuss with our client possible next steps.”

A December survey by the United Educators of San Francisco union found that 70 percent of its members said they were renters, and 59 percent were worried that the high cost of living in San Francisco could prevent them from continuing to work and live in the city. A Chronicle analysis in May found that an average city teacher, who earns a salary of $65,240, would have to pay 64 percent of his or her income to afford a one-bedroom unit in the city at the median monthly rent of $3,500. That’s more than twice the recommended federal guidelines for how much salary should be spent on housing.

Ken Tray, political director at United Educators and a longtime social studies teacher, called the timing of the ruling “unfortunate.”

“We have a new school year and what we are pushing for in the district is stability, safety and support. How do you attain stability, safety and support? Well, you have a stable teaching force and a stable staff,” he said. “This is what the groundbreaking Campos legislation helped provide — an extra layer of protection from eviction during this crisis of affordability.”

Zacks said the ruling is just the latest example of San Francisco lawmakers passing legislation that is inconsistent with state law.

“The judicial system is currently the only hope for vindicating the rights of property owners under the assault of short-sighted, ill-advised, counterproductive, and illegal San Francisco legislation,” Zacks said.

J.K. Dineen is a San Francisco Chronicle Staff Writer. Email: jdineen@sfchronicle.com Twitter: @sfjkdineen

Teacher pay

Read The Chronicle’s project on teachers leaving the unaffordable city: http://projects.sfchronicle.com/2016/teacher-pay/