A California Superior Court judge ruled Tuesday that the state's teacher tenure laws were unconstitutional, dealing a severe blow to the public sector unions who had fought to keep the status quo intact.

Judge Rolf Treu ruled in favor of nine students who sued the state, saying the tenure policies undermined their education by making it almost impossible for bad teachers to be fired.

California law allows teachers to become eligible for tenure after less than two years on the job. Firing a teacher, on the other hand, could take as long as a decade and cost the state as much as $450,000 — when it even tries. In practice, dismissals are rare.

Teachers unions defended the laws as necessary for job security, persevering academic freedom and to attract talented educators.

The students countered that teachers often came to class poorly prepared and gave them little motivation.

Treu found the students' case more compelling and noted that the current system hurts the disadvantaged the most: "Substantial evidence presented makes it clear to this court that the challenged statutes disproportionately affect poor and/or minority students."

He relied heavily on this point, saying the evidence was not only clear but "shocks the conscience." The decision even begins by citing Brown v. Board of Education, the landmark 1954 school desegregation case.

"There is also no dispute that there are a significant number of grossly ineffective teachers currently active in California classrooms," Treu wrote. Citing the evidence presented in the case, he put the number at between 2,750 to 8,250, adding that this has a "direct, real, appreciable and negative impact" on students.

The case, named Vergara v. California, was filed in 2012. The state and the California Teachers Association, the state branch of the National Education Association, were the defendants.

The ruling orders that five state education code statutes relating to teacher tenure be stayed pending appeals court review.

California has one of the largest school systems in the nation with an estimated 275,000 active teachers and 6 million students.

The case has been closely watched, especially by the education community, state and local government officials and activists.

"It will encourage reformers and families in other states to file similar suits to end similar laws on the books," said RiShawn Biddle, editor of the website Dropout Nation.

Kara Kerwin, president of the nonprofit Center for Education Reform, agreed, calling it a "monumental affirmation" but added that it will not mean overnight change, noting that the appeals process would have to play out first.

National Education Association President Dennis Van Roekel called the ruling "deeply flawed" and portrayed it as little more than an attack on teachers by conservative groups.

"Let's be clear: This lawsuit was never about helping students, but is yet another attempt by millionaires and corporate special interests to undermine the teaching profession and push their own ideological agenda on public schools and students while working to privatize public education," he said.

American Federation of Teachers President Randi Weingarten tweeted: "Sad day in Cali- but not unexpected that lower court would find that for students to win, teachers have to lose #Vegara".