A federal court judge has ruled Immigration Minister Peter Dutton has a duty of care to ensure an African refugee is able to access a safe and legal abortion.
The immigration department sent the woman - who was raped on Nauru while unconscious and suffered a suspected epileptic seizure in January - to Port Moresby, Papua New Guinea for a termination.
Abortions are illegal under the PNG criminal code.
The woman wanted to have the procedure done in Australia.
Justice Mordecai Bromberg handed down his judgment in Melbourne on Friday evening, stating the offer of an abortion in PNG had "safety and lawfulness risks that a reasonable person in the minister's position would have avoided".
Thus the minister did not discharge his duty of care, the judgment said.
The woman, known publicly as S99, has been in limbo in a Port Moresby hotel for a month.
The judgment says an abortion for the woman is not straight forward because of her neurological condition, poor mental health and physical complications caused by a procedure she was subjected to as a young girl.
The woman has no independent means, she remains dependent on the minister for food, shelter, security and healthcare, the judgment says.
Justice Bromberg did not require the department to bring the woman to Australia for the abortion but said she can't be forced to have one in PNG.
Australian Greens senator Sarah Hanson-Young called for the woman to be brought to the mainland for proper medical care.
"The court has reprimanded the immigration minister for, once again, ignoring doctors' advice," she said in a statement.