Defendant Evelyn Hernandez, 21, has already served three years of the sentence handed down after prosecutors said she had induced an abortion.
An appeals court in El Salvador on Monday acquitted a 21-year-old rape victim accused of killing her stillborn baby, in a case closely watched by rights groups.
The court in San Salvador overturned a 30-year sentence imposed on Evelyn Hernandez, who was convicted under the Central American country's strict anti-abortion laws in 2017.
Hernandez's lawyer, Bertha Maria Deleon, triumphantly announced the verdict on Twitter: "Acquitted! Yes we could."
Her legal team had won a re-trial after appealing the 2017 verdict on the grounds that it had failed to take into account ke y forensic evidence that indicated that the baby had choked in the womb.
Hernandez gave birth in April 2016 in the bathroom of her home in the central Cuscatlan region. She was 18 years old and eight months pregnant.
She said her son was stillborn but a court in the city of Cojutepeque convicted her of murder after prosecutors said she was culpable of not having sought prenatal care.
Hernandez said she had not known she was pregnant and gave birth on the toilet after feeling abdominal pains.
Hernandez became pregnant as a result of a rape which she did not report out of fear because her family had been threatened.
A report by the Inter-American Commission on Human Rights in January urged El Salvador to revise the cases of women sent to prison for having abortions.
El Salvador should "carefully review the convictions" of each of the women, the report concluded.
In March, three women serving 30-year sentences for aggravated homicide after losing their babies by miscarriage were released from prison.
But around 20 women remain locked up in similar cases, serving long sentences.
Many women who suffered miscarriages or complications in pregnancy ended up being found guilty of voluntary abortions, the Inter-American rights commission said.
El Salvador's law against abortions provided for prison sentences of between two and eight years, but courts often found the women guilty of the more serious crime of aggravated homicide, which carries punishment of up to 50 years behind bars.