A Salvadoran court has acquitted a rape victim accused of homicide after giving birth to a stillborn baby in a toilet in a case that drew international attention to the socially conservative nation's strict abortion ban.

Key points: In February, the Supreme Court ordered Ms Hernandez be released and retried

In February, the Supreme Court ordered Ms Hernandez be released and retried Ms Hernandez was raped by a gang member and said she was unaware of her pregnancy

Ms Hernandez was raped by a gang member and said she was unaware of her pregnancy More than 140 women were sentenced to up to 40 years in similar cases between 2000 and 2014

Evelyn Beatriz Hernández, now 21, had served 33 months of a 30-year prison sentence when her conviction was overturned in February for lack of evidence and a new trial was ordered. Prosecutors had asked for a 40-year sentence.

The retrial was a first for such a case in the Central American nation, where prosecutors aggressively pursue legal cases against women who have miscarriages or other obstetric emergencies, accusing them of murder.

"Thank God, justice was done," Ms Hernandez, in tears, told a cheering crowd outside the courthouse.

"There are many women who are still locked up and I call for them to be freed soon, too."

Ms Hernandez was raped by a gang member and said she was unaware of her pregnancy until just shortly before she gave birth to a stillborn son in April 2016.

'Victory for the rights of women'

Supporters celebrated outside the courthouse on hearing of Ms Hernandez's acquittal. ( AP: Salvador Melendez )

In February, the Supreme Court ordered Ms Hernandez released and retried, saying that the original judge's decision was based on prejudice and insufficient evidence.

"This is a resounding victory for the rights of women in El Salvador," Erika Guevara-Rosas, Amnesty International's Americas director, said about the verdict.

"It reaffirms that no woman should be wrongly accused of homicide for the simple fact of suffering an obstetric emergency."

Some 147 Salvadoran women were sentenced to up to 40 years in prison in such cases between 2000 and 2014, according to the Citizen Group for the Decriminalization of Abortion, a local rights group.

The group said it would seek fresh reviews of at least 16 similar cases.

Women prosecuted under El Salvador's hard-line abortion laws include those who have suffered stillbirths after home deliveries as well as abortions induced because of medical emergencies.

'No way to prove a crime'

In February, the Supreme Court ruled that the original judge's decision was based on prejudice and insufficient evidence. ( AP: Salvador Melendez )

Ms Hernández's foetus was at 32 weeks in 2016 when she felt intense abdominal pains and delivered it into an outdoor toilet. It was later found lifeless in the septic tank.

Her mother said she found her passed out next to the latrine.

Both women said they didn't know there was a foetus in the tank, but prosecutors didn't believe them and pressed charges.

Forensic experts were unable to determine whether it died in the uterus or in the septic tank.

"We believe the judge has been very fair in his ruling," defence lawyer Bertha María Deleón said.

"He has said that there was no way to prove a crime and for that reason he absolved her."

El Salvador is one of three Central American nations with total bans on abortion.

Amnesty International urged El Salvador "to end the shameful and discriminatory practice of criminalising women once and for all by immediately revoking the nation's draconian anti-abortion laws".

ABC/wires