U.S. District Judge Myron Thompson ruled in favor of inmates who filed suit to end the longstanding practice. Thompson says the state's policy violates federal disabilities law.

Thompson said the state and inmate attorneys will have time to propose a way to bring state prisons into compliance with his order.

The American Civil Liberties Union, which filed the lawsuit on behalf of seven HIV-positive inmates, called the decision "historic." State officials did not immediately respond to requests for comment.

Alabama and South Carolina are the only states that segregate HIV-positive prisoners. The class-action lawsuit accused the state of violating the Americans with Disabilities Act.

ACLU attorney Margaret Winter, who was lead counsel for the plaintiffs during a month-long trial, called the decision historic.

"It spells an end to a segregation policy that has inflicted needless misery on Alabama prisoners with HIV and their families," Winter said.

In his 153-page opinion, Thompson recounted the history of the AIDS scare in the 1980s and noted the extreme rarity of HIV being transmitted by any means other than the sharing of bodily fluids, particularly during unprotected sex between males or between a man and a woman.

"It is not transmitted through casual contact or through the food supply," he wrote. "A person would have to drink a 55-gallon drum of saliva in order for it to potentially result in a transmission. There is no documented case of HIV being sexually transmitted between women."

Alabama's policy resulted from a "panic" over AIDS in prisons, Thompson wrote. While other states have ended similar practices, he said, Alabama hasn't because of "outdated and unsupported assumptions about HIV and the prison system's ability to deal with HIV-positive prisoners."

Bias from agency leaders is at the heart of the plan to segregate infected inmates, Thomas said.

Olivia Turner, executive director of the ACLU of Alabama, said Thompson's ruling will end a policy "that treated human beings like cattle to be tagged and herded. "She called the ruling "a tremendous victory for human rights."

Thompson says he still must decide a part of the suit involving work-release inmates.