The Supreme Court of El Salvador has refused to allow a seriously ill pregnant woman to have an abortion, even though her foetus has almost no chance of survival.
Lawyers for the young woman - who suffers from lupus and kidney failure - had argued that continuing the pregnancy would place her life at risk.
The foetus itself is missing part or all of its brain.
All abortions are prohibited in El Salvador under any circumstances.
The constitution in the majority Roman Catholic country protects the right to life "from the moment of conception".
The 22-year-old woman - referred to as "Beatriz", not her real name - is said to be in fragile health, suffering from the chronic immune disorder lupus as well as kidney failure.
Tests suggest her 26-week-old foetus is developing without a complete brain, a condition called anencephaly. Almost all babies born with this condition die before or shortly after birth.
A medical committee at her maternity hospital, the Ministry of Health and rights groups had all supported Beatriz's request to terminate her pregnancy, but judges at the Supreme Court voted four-to-one to reject the woman's appeal.
In their ruling, the judges said: "This court determines that the rights of the mother cannot take precedence over those of the unborn child or vice versa, and that there is an absolute bar to authorising an abortion as contrary to the constitutional protection accorded to human persons 'from the moment of conception'."
The judges said that Beatriz's health was "stable", although they recognised this could change, ordering doctors to continue to monitor her health and provide all necessary treatment.
Judge Rodolfo Gonzalez, one of the four judges to rule against allowing Beatriz to have an abortion, said the constitutional court could not be turned into a "tribunal to allow the interruption of pregnancies".
Judge Gonzalez said he had not been convinced Beatriz was at risk of dying if the pregnancy was allowed to continue.
He said the case, and the great number of groups and people who had wanted to offer their opinion on it, had shown there was a need to discuss abortion more widely in El Salvador.
Florentin Melendez was the only one of the five judges to rule in favour of Beatriz, but said this did not mean he backed abortions.
He said he believed the court should have ruled in her favour to "guarantee that the medical personnel would not omit [any treatments] and would act diligently at all times, without having to recur to legal authorisation to protect the life of the mother and the human being she is carrying in her womb".
There was no immediate response from Beatriz's lawyers to the ruling.
Campaigners for the legalisation of abortion in cases where the mother's or foetus's life are at risk have condemned the ruling.
Morena Herrera, director of a campaign group which has supported Beatriz's case, said it was "irresponsible".
She argued that the judges had failed to consider the delicate state of health of the foetus, which she said would have no chance of surviving after birth.
"The only life we can save here is that of Beatriz," she said.
Ms Herrera said the group would look into ways of moving Beatriz out of El Salvador so she could receive the treatment they said she needed.
Doctors who support a termination have argued that the risk to Beatriz's health will grow as her pregnancy advances, and that if she suffers a health crisis it will be more difficult to treat the further into her pregnancy she is.
Doctors who perform an abortion in El Salvador and the mothers who undergo it face arrest and criminal charges.