(CNN) They spent nearly 15 years in prison for a crime so unspeakable they simply became known as the "San Antonio Four."

Elizabeth Ramirez, Kristie Mayhugh, Cassandra Rivera and Anna Vasquez were convicted in the late 1990s of gang-raping two little girls who were Ramirez's nieces.

They had recently come out as lesbians and prosecutors used their sexuality as a motive. The women refused plea deals and took the rare step of testifying in their defense to say they had done no wrong.

After years of fighting to clear their names, the state's highest court exonerated them on Wednesday, saying they had achieved the "Herculean" task of proving their innocence. The ruling overturns their convictions, prevents further prosecutions and paves the way for the women to potentially seek millions of dollars in compensation from the state.

"Those defendants have won the right to proclaim to the citizens of Texas that they did not commit a crime. That they are innocent. That they deserve to be exonerated," Texas Court of Criminal Appeals Judge David Newell wrote in the majority opinion. "These women have carried that burden. They are innocent. And they are exonerated."

The Bexar County District Attorney's Office, which prosecuted the case, welcomed the decision.

"It has been a long legal process for these women and our office has worked with the defense to ensure justice was done in this case. With today's announcement we believe the Texas Court of Criminal Appeals' decision did that," District Attorney Nico LaHood said in a statement. "I pray [for] peace and a new beginning for them."

The women known as the San Antonio Four in 2015.

An attack on their sexuality

The allegations in 1994 rocked San Antonio and made national headlines, becoming the subject of the documentary "Southwest of Salem." In an era when more gays and lesbians were coming out and mainstreaming, many saw the allegations as an indictment of the women's sexuality, especially as the case against them began to unravel.

"I think the only reason that the investigation was seriously pursued, why there wasn't more skepticism about the preposterous allegations in the first place, was because these four women had recently come out as gay, that they were openly gay," attorney Mike Ware told CNN's Jean Casarez in April

The case stemmed from allegations from Ramirez's nieces, ages 7 and 9. They stayed with their aunt for a few days in the summer of 1994 while their mother was on vacation. During their stay, Mayhugh, Vasquez and Rivera visited Ramirez's apartment at various points.

When they returned home they told their grandmother the women pinned them down and sexually assaulted them on two occasions. Their accounts varied in subsequent statements to police and the examining doctor and in trial testimony on several points, from the weapon used to subdue them to when the incidents took place, the Supreme Court opinion noted.

Such inconsistencies were "easy to set aside," Newell wrote, given testimony from the state's medical expert. Dr. Nancy Kellogg that said the girls had vaginal injuries that could only come from "painful trauma" caused by penetration with a foreign object.

Bexar County prosecutors portrayed Ramirez as the ringleader and tried her first. She was convicted in 1997 of aggravated sexual assault of a child and indecency with a child, despite her testimony that she had no idea "how they could even think of me doing something like that." She was sentenced to 37.5 years in prison.

The remaining women were tried together in 1998 and were each convicted of two counts of aggravated sexual assault of a child and two counts of indecency with a child. All three were sentenced to 15 years in prison on the aggravated sexual assault charges and 10 years for the indecency charges.

The cases unravel

The convictions began to unravel several years ago when one of Ramirez's two nieces, now in her twenties, stepped forward to say she had lied.

Members of her family coached her, she told authorities, to make up a story because of their anger toward Ramirez's sexuality. Her father in particular coerced them so he could gain leverage in a custody battle, she said.

Soon after, Kellogg recanted her testimony based on new science that showed her findings regarding the girls' injuries were medically inaccurate.

With the new evidence, Ware and the Innocence Project of Texas filed for post-conviction relief to have the verdicts overturned.

A story 'no rational juror' would believe

A Bexar County District Court allowed Mayhugh, Rivera and Ramirez to be released from prison in 2013 while the court considered their request. Vasquez had just been released on parole.

The motion worked its way through the Texas courts. After a two-day hearing during which the niece and the doctor retracted their initial claims, a judge recommended in February 2016 that the convictions be vacated. But it declined to fully exonerate them without a full recantation from the second niece.

The Court of Appeals sided with the lower court's ruling that "more likely than not," the jury would not have convicted the women had they heard about the new scientific evidence. It also relied heavily on the niece who came forward, saying that her recantation coupled with the lack of reliable forensic evidence would lead "no rational juror" to find any of the defendants guilty.

The Innocence Project of Texas celebrated the news in a Facebook post that includes a recent picture of the women and their lawyer.

"Plenty to be thankful for this Thanksgiving season, including the full exoneration of Anna Vasquez, Elizabeth Ramirez, Cassandra Rivera, and Kristie Mayhugh, also known as the San Antonio 4!"