One of the teenager's lawyers, Dennis Muñoz, had argued his client had an out-of-hospital birth in April past year because he did not even know she was pregnant and had confused labour pains with stomach ache.
Hernandez, who was 18 at the time, had been raped repeatedly by a gang member for months as part of a forced sexual relationship.
A 19-year-old rape survivor is at the center of a reproductive rights fight in El Salvador after she had a stillbirth and was sentenced to 30 years in prison for "aggravated homicide" under the nation's strict anti-abortion laws.
When authorities found the fetus in April 2016, she was charged because she had not sought prenatal care, authorities said.
Her lawyers said she did not know she was pregnant and no crime had occurred.
Morena Herrera, executive director of the Citizens' Group for the Decriminalisation of Abortion, said the teen's sentencing was based on prejudices held by the legal system.More news: Waymo Scales Back Claims Against Uber in Driverless Car Dispute
More news: Ex-Audi manager faces criminal charges in Volkswagen emissions scandal
More news: GOP leader hints at shoring up Obamacare if replacement doesn't pass.
She told the court: "I did not want to kill my son".
Abortion has been criminalised in all circumstances in El Salvador since 1998, even when the pregnancy is the result of rape, incest, or when the life or health of the pregnant woman or girl is at risk.
Cruz's attorneys will appeal the verdict and a protest against the court's decision is expected on Saturday. The 1997 reform was passed after a shadowy campaign by a small group of powerful anti-choice groups linked to the Catholic church.
Hernandez's lawyer Dennis Munoz said the decision to imprison his client was "based on morality, not the law or justice".
Amnesty International states that some women in El Salvador have received 40-year sentences following miscarriages, obstetric emergencies or abortions.
"El Salvador's anti-abortion law is causing nothing but pain and suffering to countless women and girls and their families", Amnesty's Americas director Erika Guevara-Rosas said in a statement.
"The total ban on abortion in El Salvador violates women's rights to life, health, privacy, due process and freedom from discrimination, violence and torture and other ill-treatment".
A teenager who survived rape before giving birth to a stillborn baby in a bathroom has been jailed for 30 years. The nine cross-party deputies have yet to decide whether the bill should be sent to the legislative assembly for a vote.