LOS ANGELES  A panel of federal judges ordered the California prison system on Tuesday to reduce its inmate population of 150,000 by 40,000  roughly 27 percent  within two years.

The judges said that reducing prison crowding in California was the only way to change what they called an unconstitutional prison health care system that causes one unnecessary death a week.

In a scathing 184-page order, the judges said state officials had failed to comply with previous orders to fix the prison health care system and reduce crowding.

The judges left it to state officials to come up with a specific plan within 45 days, saying there was “no need for the state to release presently incarcerated inmates indiscriminately in order to comply with our order.” They recommended remedies including imprisoning fewer nonviolent criminals and reducing the number of technical parole violators.