(CNN) -- Federal judges tentatively ruled on Monday that California must reduce the number of inmates in its overcrowded prison system by up to 40 percent to stop a constitutional violation of prisoners' rights.

California must cut the number of inmates in its prison system by up to 40 percent, judges have ruled.

"Overcrowding is the primary cause of the unconstitutional conditions that have been found to exist in the California prisons," the court concluded.

California state officials, including Gov. Arnold Schwarzenegger, immediately promised to appeal the case to the U.S. Supreme Court, if necessary.

"The governor and I strongly disagree with this ruling," said Matthew Cate, California's corrections and rehabilitation secretary. Implementing the court's ruling would result in up to 58,000 prisoners being released, Cate said, describing it as a threat to public safety.

He disputed the court's contention that the prisons are unsafe the way they are now.

But in 2006, Schwarzenegger declared a state of emergency because of "severe overcrowding" in California's prisons, saying it had caused "substantial risk to the health and safety of the men and women who work inside these prisons and the inmates housed in them."

In court documents, the judges said the state's prison system was at about 200 percent of capacity.

The ruling is the result of two class-action lawsuits on behalf of California prisoners who said medical and mental health care in the state's prisons are so inadequate that they violate the federal constitution's Eighth Amendment ban against cruel and unusual punishment.

The judges said their ruling is tentative so that the parties involved can plan accordingly, essentially giving them an opportunity to work things out themselves before an official ruling is rendered. The court suggests a two- to three-year window for reducing the number of prisoners in the system.

Those who would be released would be very low risk, according to Don Specter, director of the Prison Law Office, a group that provides free legal services to California prisoners. He said the ruling would affect those in jail for three or four months because of parole violations, those getting early release dates, and those who might qualify for early release for taking part in rehabilitation programs.

A final ruling also probably would reduce the number of people entering the prison system, with many being diverted through the courts and into rehabilitation programs instead of going to jail, Specter said.

All About Arnold Schwarzenegger • Prisons