Updated

Gov. Arnold Schwarzenegger's plan to transfer inmates out of state to relieve severe prison overcrowding is illegal, a state judge ruled Tuesday.

The governor said he would immediately appeal, citing the potential for some convicts to be released early.

"Today's disappointing ruling is a threat to public safety," Schwarzenegger said in a statement. "I will not release dangerous criminals to relieve overcrowding. The transfer of inmates is imperative to relieve the pressure on our overburdened prison system."

Schwarzenegger signed an emergency declaration in October ordering the corrections department to send thousands of inmates to private prisons in other states. Two employee unions, including the one representing guards, filed a lawsuit saying the declaration violated state law.

"Prison overcrowding in California is a crisis creating conditions of extreme peril," the judge wrote. Nonetheless, a state act that lets the state government step in when local governments are overwhelmed does not give the governor "extraordinary powers" to act without legislative approval, she added.

The unions had also argued that the transfers would have violated a provision in the state Constitution that prohibits using private companies for jobs usually performed by state workers.

The judge agreed with the unions on that point as well.