“A PRISONER WITH severe abdominal pain died after a 5-week delay in referral to a specialist. . . . A prisoner died of testicular cancer after a ‘failure of MDs to work up for cancer in a young man with 17 months of testicular pain.’ ” A prisoner suffering from serious mental illness was found “standing in a pool of his own urine, unresponsive and nearly catatonic” after being held in a “telephone-booth sized cage” without a toilet for 24 hours.

These are but a few examples of the kind of treatment inmates have been subjected to in California’s prison system. For 20 years, prisoners pressed litigation seeking improvements in mental health and medical programs. For 20 years, conditions and services remained virtually unchanged. On Monday, the Supreme Court boldly — and appropriately — drew a line.

A 5-4 majority of the court ordered the state to release some 30,000 inmates after concluding that gross overcrowding contributed significantly to the poor medical care. At one point, California prisons housed some 150,000 inmates — almost double the 80,000 they were designed to hold. “The medical and mental health care provided by California’s prisons falls below the standard of decency that inheres in the Eighth Amendment,” Justice Anthony M. Kennedy wrote for the majority. “This extensive and ongoing constitutional violation requires a remedy, and a remedy will not be achieved without a reduction in overcrowding.”

In dissent, the court’s four consistently conservative justices worried that forcing the state to release thousands of prisoners could endanger public safety. This concern is not trivial, as Justice Kennedy acknowledged, but it is manageable.

The court prudently left to the state the details of reducing the inmate population, which could include transfers to halfway houses and county or out-of-state facilities, as well as outright release. It also made clear that the state could seek more time to implement changes if the two-year deadline assigned by the court proved unworkable.

Maintaining public safety must be a priority, and California should grant freedom only to low-level and nonviolent offenders who are considered low recidivism risks. The state should also consider diverting nonviolent drug abusers to treatment programs and rescinding policies that mandate incarceration for offenders who commit technical violations of parole. To avoid overpopulation in the future, state lawmakers should rethink sentencing laws — especially long mandatory terms for nonviolent offenses.

Budget shortfalls and overcrowding have forced states across the country to reconsider their approach to law and order and the enormous costs associated with incarceration. The Supreme Court’s decision — and its implicit warning — should add even more urgency to these initiatives. If states fail to take steps to provide the type of decent and humane prison conditions demanded by the Constitution, the courts may now step in to ensure that they do.