A Salvadoran court absolved a woman previously convicted of aggravated homicide after she gave birth to a stillborn child, the woman's lawyer Bertha DeLeon said today, in a closely watched retrial that overturns a 30-year prison sentence.

Defendant Evelyn Hernandez, 21, had already served three years of the sentence handed down after prosecutors said she had induced an abortion.

The case had attracted international attention.

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

Any intentional termination of a pregnancy in El Salvador can be prosecuted as a crime, including stillbirths due to home delivery or abortions induced because of medical emergencies, with some women receiving up to 40 years in prison.

"We believe the judge was very just in the ruling. The judge said there was no way to prove a crime was committed and that is why (Hernandez) was acquitted," said Ms DeLeon.

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 Decriminalisation of Abortion, a local rights group.

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

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.