In what is being billed as one of the biggest prison release orders in history, the U.S. Supreme Court on Monday ordered California government to reduce its prison population by nearly 33,000 over a period of two years to avoid serious constitutional violations.

The Supreme Court, in a sharply divided 5-4 decision, upheld an injunction by a three-judge panel of a lower court that had ordered California to overhaul its prison system that has held nearly twice its designed capacity.

The Supreme Court said California's current prison system endangered guards as well as inmates.

The apex court said grossly inadequate provision of medical and mental health care resulted in needless suffering and death. It ruled that California's prison population must be reduced from 143,000 to 110,000 by mid-2013.

The largest ever prisoner release order from a federal court was in 2009 when California was ordered to reduce the prison
population by 46,000 inmates within 2 years to get down to what judges decided would be a reasonable level.

Justice Anthony Kennedy, joined by the court's more liberal justices - Justices Ruth Bader Ginsburg, Stephen Breyer, Sonia Sotomayor and Elena Kagan - wrote the majority opinion, citing evidence from two decades of litigation, including a prisoner dying of testicular cancer after prison doctors failed to do a work up for cancer for the prisoner, who was in pain for 17 months; wait times for treatment of mentally ill inmates being as high as 12 months; suicidal inmates held for 24 hours in telephone booth-sized cages without toilets; backlogs of up to 700 prisoners waiting to see a doctor; up to 54 inmates sharing a single toilet; gyms converted into triple-bunked living quarters that breed disease; and violence victimizing guards and inmates alike.

In one case, a prisoner was assaulted in a crowded gymnasium, prison staff did not even learn of the injury until the prisoner had been dead for several hours, Kennedy wrote.

Though Kennedy expressed grave concern in releasing prisoners in large numbers, yet the prison conditions violated the Eighth Amendment's prohibition against cruel and unusual punishment.

A prison that deprives prisoners of basic sustenance, including adequate medical care, is incompatible with the concept of human dignity and has no place in civilized society, Kennedy wrote in the 52-page majority opinion.

The dissenters, led by Justice Antonin Scalia, called the decision staggering and absurd and said it takes the federal courts wildly beyond their institutional capacity.

The dissenters, including Chief Justice John Roberts and Justices Clarence Thomas and Samuel Alito, warned the court was freeing the equivalent of three Army divisions of criminals and was gambling with the safety of the people of California.

The majority is gambling with the safety of the people of California, Alito wrote. I fear that today's decision, like prior prisoner release orders, will lead to a grim roster of victims. I hope that I am wrong.

Alito also warned that the Constitution does not give federal judges the authority to run state penal systems. Decisions regarding state prisons have profound public safety and financial implications, and states are generally free to make these decisions as they choose, he wrote.

The ruling ends a legal battle that began in 1990, when inmates sued the state, challenging the substandard treatment of mentally ill inmates. In 2001, they were joined by another class action lawsuit with prisoners suing over medical care for purposes of the court's decision.

In 2006, a federal judge appointed a receiver to manage the health care system, saying state officials were unable to comply with constitutional standards. After a trial in 2009, a three-judge panel said the system could be repaired only if the state first addressed overcrowding. At the time, there were 156,000 inmates in a system designed for 80,000.

At issue was whether federal judges had the power to order the release of state prisoners as a necessary means of curing a constitutional violation.

Many rights groups have hailed the ruling, saying it was high time the state overhauled its prison system.

California locks up too many people who pose no threat to public safety and keeps them locked up for too long, said Allen Hopper, an American Civil Liberties Union (ACLU) attorney in San Francisco.

Donald Specter, an attorney for the inmates and the director of the nonprofit Prison Law Office, has welcomed the ruling. This landmark decision will not only help prevent prisoners from dying of malpractice and neglect but it will make the prisons safer for the staff, improve public safety and save the taxpayers billions of dollars, he said.

It costs California $49,000 annually to house an inmate, or almost seven times what we spend on each child in our public schools.

We want to see that money go into community based programs that will help those prisoners transition into our society, said Prison reform advocate Debbie Reyes of the California Prison Moratorium Project.

California Governor Jerry Brown's administration was critical of the ruling but said the state will try to comply with it without releasing any dangerous criminals. As we work to carry out the Court's ruling, I will take all steps necessary to protect public safety, Brown said in a statement.

Brown said Assembly Bill 109 could accomplish what the Supreme Court wants and though the measure has been approved, the legislature has refused to fund it.

The Assembly Bill 109, which calls for a realignment of the prison and parole system, shifts to counties the responsibility for incarcerating many low-risk inmates. Under the bill, up to 30,000 state prison inmates could be transferred to county jails over three years. First, however, state officials must agree on a way to pay for it.

Under former Governor Arnold Schwarzenegger, the state's lawmakers had sped up the releases of some low-risk inmates and stopped returning parolees to prison for minor violations. Declaring the state's overcrowded prisons a state of emergency in 2006, Schwarzenegger had transferred nearly 10,000 prisoners to other states.