A federal judge on Tuesday ordered state prison officials to provide taxpayer-funded sex-reassignment surgery to a transgender inmate serving life in prison for murder.

Michelle Kosilek was born male but has received hormone treatments and now lives as a woman in an all-male prison. Robert Kosilek was convicted of murder in the killing of his wife in 1990.

U.S. District Judge Mark Wolf is believed to be the first federal judge to order prison officials to provide sex-reassignment surgery for a transgender inmate.

Kosilek first sued the Massachusetts Department of Correction 12 years ago. Two years later, Wolf ruled that Kosilek was entitled to treatment for gender-identity disorder but stopped short of ordering surgery. Kosilek sued again in 2005, arguing that the surgery is a medical necessity.

In his ruling Tuesday, Wolf found that surgery is the "only adequate treatment" for Kosilek's "serious medical need."

"The court finds that there is no less intrusive means to correct the prolonged violation of Kosilek's Eighth Amendment right to adequate medical care," Wolf wrote in his 126-page ruling.

Prison officials have repeatedly cited security risks in the case, saying that allowing Kosilek to have the surgery would make him a target for sexual assaults by other inmates.

But Wolf, who was appointed to the federal bench by President Ronald Reagan in 1985, found that the security concerns are "either pretextual or can be dealt with." He said it would be up to prison officials to decide how and where to house Kosilek after the surgery.

Diane Wiffin, a spokeswoman for the prisons department, said the agency would have no immediate comment on the ruling.

"We are reviewing the decision and exploring our appellate options," Wiffin said.

In a telephone interview last year with The Associated Press, Kosilek said the surgery is a medical necessity, not a frivolous desire to change his appearance.

"Everybody has the right to have their health care needs met, whether they are in prison or out on the streets," Kosilek said. "People in the prisons who have bad hearts, hips or knees have surgery to repair those things. My medical needs are no less important or more important than the person in the cell next to me."

Wolf noted in his ruling that the Department of Correction's own medical experts testified that they believe surgery was the only adequate treatment for Kosilek.

The department's ex-commissioner Kathleen Dennehy testified that providing Kosilek the surgery would present insurmountable security concerns, but Wolf said Kosilek had proven that those purported concerns masked the real reason for denying surgery: "a fear of controversy, criticism, ridicule and scorn."

Kosilek's lawsuit has become fodder for radio talk shows and lawmakers who say the state should not be forced to pay for a convicted murderer's sex-change operation -- which can cost up to $20,000 -- especially since many insurance companies reject the surgery as elective.

Inmates in Colorado, California, Idaho and Wisconsin have sued unsuccessfully to try to get the surgery, making similar arguments that denying it violates the U.S. Constitution's protection against cruel and unusual punishment.

Wolf noted that Kosilek's gender-identity disorder has caused Kosilek such anguish that he has tried to castrate himself and twice tried to commit suicide, including once while on Prozac.

Kosilek's lead attorney, Frances Cohen, called the decision courageous and thoughtful.

"We feel very grateful that the judge listened very carefully to the medical experts and has given Michelle Kosilek what the prison doctors had recommended," Cohen said.