A California appeals court handed teacher unions a big victory Thursday by reversing a trial judge's ruling that found tenure deprived some students of a good education.

The 2nd District Court of Appeal said a group of nine students who sued the state had failed to show California's hiring and firing rules were unconstitutional.

"The court's job is merely to determine whether the statutes are constitutional, not if they are 'a good idea,'" presiding Justice Roger Boren wrote in the 3-0 opinion.

A Los Angeles Superior Court judge who found evidence to "shock the conscience" had sided with students two years ago who claimed that incompetent teachers were almost impossible to fire because of tenure laws and that schools in poor neighborhoods were dumping grounds for bad teachers.

The ruling was stayed pending appeal, so it never went into effect, but if upheld had threatened to shake up public schools that teach more than 6 million students from kindergarten through 12th grade statewide.

In reversing that decision, the appellate panel said the trial highlighted problems with tenure and layoff statutes and showed the "deleterious impact" of staffing decision on poor and minority students. But it said state law wasn't to blame.

"Some principals rid their schools of highly ineffective teachers by transferring them to other schools, often to low-income schools," Boren wrote. "This phenomenon is extremely troubling and should not be allowed to occur, but it does not inevitably flow from the challenged statutes."

A lawyer for the plaintiffs said they were disappointed, but called it a "temporary setback" and expected to appeal to the California Supreme Court.

"The Court of Appeal's decision mistakenly blames local school districts for the egregious constitutional violations students are suffering each and every day," attorney Theodore Boutrous Jr. said in a written statement. "The irrational, arbitrary, and abominable laws at issue in this case shackle school districts and impose severe and irreparable harm on students."

The closely watched case highlighted tensions between teacher unions, school leaders, lawmakers and well-funded education reform groups over whether policies like tenure and firing teachers with the least seniority keep ineffective instructors in the classroom, particularly in already low-performing schools.

Teachers have long argued that tenure protects them from being fired on a whim, preserves academic freedom and helps attract talented teachers to a profession that doesn't pay well.

Attorney Michael Rubin, who defended teachers unions in the case, said the court's decision was "huge."

"It puts to rest — we believe forever — the constitutional attacks on job security for teachers," Rubin said.

The Vergara v. State of California lawsuit, including Beatriz Vergara among the public school student plaintiffs, was backed by Students Matter, a nonprofit group founded by Silicon Valley entrepreneur David Welch.

Attorneys for the state and teachers unions had argued that the case was never about helping students and should be overturned because no evidence was presented showing the disputed statutes were the cause of educational inequalities.

A similar lawsuit was filed in New York after the Vergara decision, contending that state's teacher tenure and layoffs by seniority laws deprive students of a sound, basic education as guaranteed under the state constitution. Lawyers for New York's teachers union have asked for the case to be dismissed.