Lisa Bul / AP file Robert Kosilek sits in Bristol County Superior Court, in New Bedford, Mass., Jan. 15, 1993. Kosilek, now named Michelle, has since undergone hormone treatment for gender-identity disorder.

A federal judge in Boston on Tuesday ordered the Massachusetts Department of Corrections to provide sex-change surgery to a transgender inmate serving life in prison for murder, ruling that failure to do so violated the prisoner's Eighth Amendment right to adequate treatment.

U.S. District Judge Mark Wolf ruled in the case of Michelle Kosilek, born as Robert Kosilek, who is serving a life sentence without the possibility of parole for murdering his wife in 1990. Kosilek who identifies as female, has received hormone treatments and lives as a woman in an all-male prison.

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.

According to The Associated Press, Wolf is the first federal judge to order prison officials to provide the surgery for a transgender inmate.

"This is a very big victory," Kosilek's attorney, Frances S. Cohen told NBC News. Although the ruling is not binding outside the state, she said: "I think it will be very influential beyond Massachusetts."

It was not known whether the Massachusetts Department of Corrections would appeal the ruling.

After Kosilek first sued the department 12 years ago, Wolf ruled that Kosilek was entitled to treatment for gender-identity disorder, but stopped short of ordering surgery. In 2002, Kosilek started a trial of hormones, with the intention of reevaluating the need for surgery. She sued again in 2006.

The department was supposed to reevaluate after one year, according to Cohen.

"In 2006, it became clear that they were not doing this in good faith," she said.

According to the judge's statement, Kosilek's anguish from gender identity disorder caused him to "attempt to castrate himself and to attempt twice to kill himself while incarcerated.”

Prison officials repeatedly cited security risks in the case, saying that allowing the surgery would make Kosilek a target for sexual assault.

But Wolf found that the department's security concerns are "either pretextual or can be dealt with by the DOC." He said it is up to prison officials to decide how and where to house Kosilek after the surgery.

"The DOC has the discretion to make good faith, reasonable decisions concerning security if the surgery genuinely creates or increases any risk to Kosilek or others," he wrote.

The Massachusetts ruling came just two weeks after the American Psychiatric Association published its updated position strongly endorsing access to treatment for transgender and gender variant individuals, noting that they "can benefit greatly from medical and surgical transition treatments."

"There is increased awareness that this kind of care is not particularly special," said Kristina Wertz, director of programs and policy at the nonprofit Transgender Law Center in San Francisco. "It's just medically necessary care. Our prison systems have an obligation to provide medically necessary health care."

This article includes reporting by The Associated Press.

Follow Kari Huus on Facebook

More content from NBCNews.com:

Follow US News from NBCNews.com on Twitter and Facebook