U.S. District Judge Thelton Henderson instructed corrections officials to transfer most black, Filipino and medically at-risk inmates because they are more vulnerable to health problems from valley fever. The fungal infection originates in the soil of the San Joaquin Valley, where Avenal and Pleasant Valley state prisons are located.
He gave the state 90 days to fully comply.
About 3,250 of the two prisons' 8,100 inmates fall into the categories covered by the judge's ruling. But Henderson said inmates among those groups who already have had the disease do not have to be moved.
He also altered the recommendation from the court-appointed official who oversees prison medical care to exclude inmates over age 55, although that category of inmates could be included at a later date.
It is not immediately clear how many of the inmates will actually have to be transferred based on the judge's revised criteria, said Joyce Hayhoe, a spokeswoman for federal receiver J. Clark Kelso, who made the recommendations to Henderson.
Hayhoe said it makes sense for the judge to exclude inmates who previously contracted the infection because they can't get the illness twice.
Henderson criticized Gov. Jerry Brown's administration for delaying significant response to the problem for years and for its recent proposal to delay action for several months until the U.S. Centers for Disease Control can complete health studies at the prisons.
Prison officials are moving about 600 vulnerable inmates by August, but "are unwilling to exclude other inmates whom they know are at an increased risk of severe disease, which may lead to death," the judge wrote. "Defendants have therefore clearly demonstrated their unwillingness to respond adequately to the health care needs of California's inmate population."
Henderson gave the state seven days to begin moving the inmates from the two prisons located about 10 miles apart and 175 miles southeast of San Francisco.
Deborah Hoffman, a spokeswoman for the Department of Corrections and Rehabilitation, said the state is reviewing Henderson's order.
The ruling is the latest legal setback for the Democratic governor, who is trying to persuade federal judges that the state has improved prison medical and mental health care enough to meet constitutional standards. A three-judge panel that includes Henderson last week gave the state until year's end to reduce the prison population by nearly 10,000 inmates as the best way to improve conditions.
Brown filed a one-paragraph notice on Monday that the state will appeal the order to reduce prison populations to the U.S. Supreme Court, as it previously announced.
Henderson's valley fever order came a week after a hearing in his San Francisco courtroom in which attorneys representing inmates said 18 prisoners died in 2012 and January 2013 from complications relating to the fungus.
"The order is absolutely necessary to preserve people's lives and health because state officials have been simply unwilling to take appropriate action when there's a clear and imminent danger to prisoners' lives. It's the most recent example of the state's inability to protect the health of prisoners," said Don Specter, director of the nonprofit Prison Law Office that successfully sought both the valley fever and prison crowding orders.
Brown's administration has said it would have difficulty moving so many inmates while the state also tries to reduce prison crowding statewide.
The Associated Press contributed to this report.