A 12-year-old Australian girl with a history of suicide attempts was forced to seek a judge’s approval to end an unwanted pregnancy under strict abortion laws.

The girl gained a Queensland supreme court order allowing her to have an abortion after a month dealing with a string of medical, mental health and child safety professionals, who all found her decision as being in her best interests.

Her case has prompted a vow by an independent Queensland MP, Rob Pyne, to introduce a bill to strike abortion from the state’s criminal code at the next sitting of parliament.

The 20 April ruling by Justice Duncan McMeekin, published on Tuesday, came nine weeks after the girl, identified only as “Q”, fell pregnant to a boy her own age who still does not know about it.

Q told the court that her “very stressful” pregnancy followed months of emotional turmoil during which she had run away from home, cut herself and twice attempted suicide.

A psychiatrist and her parents held concerns that Q was at real risk of further self-harm or suicidal behaviour if forced to carry a child to birth. McMeekin was satisfied Q had independently arrived at her decision to end her pregnancy, a conviction she held for more than a month while having consultations with a general practitioner, a social worker, two obstetricians and a psychiatrist.

“She has no wish to be a mother,” McMeekin said. “Unsurprisingly, she feels that she is not fitted for that task.”

However, McMeekin said her consent alone did not make the abortion lawful under Queensland’s criminal code, which required it to be “authorised or justified by law”.

The court order was sought in Rockhampton by the Central Queensland hospital and health service, where Q is a patient.

Pyne, who holds part of the balance of power in the state parliament, said the legal process forced on the girl was “cruel and unusual treatment” that should not be repeated.

“Because of cases like this I undertake to introduce a private member’s bill into the Queensland parliament to have abortion removed from the criminal code, so this sort of thing doesn’t happen again,” Pyne said.

“We are talking about someone who is vulnerable and I would say having to go through this process is cruel and unusual treatment to dish out to a 12-year-old child.”

In Queensland, it is illegal to carry out an abortion unless a doctor decides it is necessary to avoid danger to a woman’s mental and physical health. The need to establish legal competency of a patient has meant doctors are reluctant to proceed in cases of children without the explicit authority of a court.

McMeekin ruled the girl be given the drugs mifepristone and misoprostol to end the pregnancy by 23 April. Failing that, he ordered a surgical abortion by Wednesday.

The judge found the evidence was “all one way” in favour of an abortion, citing the risk of “significant and possibly lifelong” mental health problems if it was not allowed.

The pregnancy occurred with the backdrop of the girl’s “significant difficulties” in adjusting to her parents’ separation, “with episodes of self-harm, absconding from school and thoughts of suicide”.

Her mother, who backed Q’s account of suicide attempts and said she was in no position to assist with bringing up a child, flagged a “very real risk of self harm and or suicidal behaviour if her pregnancy was to continue”.

The psychiatrist said the “most accurate predictor of future behaviour is past behaviour, and [Q] has a very recent history of self harm and suicidal thoughts”.

“It is my opinion that termination of pregnancy would reduce those risks,” the psychiatrist said.

McMeekin said an obstetrician advising Q said the “risks of continuing the pregnancy (some of which were potentially life threatening) ‘far outweigh’ the risks involved in terminating”.

“He also commented that there were psycho-social implications of having a child at the age of 12, with a ‘lifelong burden, which is likely to affect mental health’,” the judge said.

The child safety department, which had earlier involvement with the family, also supported the abortion.

Caroline de Costa, an abortion law reform advocate and a professor of obstetrics at James Cook University, told the Australian that doctors were “being very cautious because of the way the law is written”.

“There is caution on the part of doctors in the case of a 12-year-old,” she said.

“Doctors intending to perform the procedure must now speak with the young woman and determine whether she is legally ... competent, whether she can make a decision herself about whether she should terminate the pregnancy or not.”

A Queensland court order was sought in 2008 to allow a girl, aged 12 but with the intellect of a six-year-old, to undergo a later-term abortion.

Larissa Waters, a federal Greens senator, said the striking out of Queensland’s “archaic, harmful laws that treat abortion as a crime in some circumstances... is long overdue”.

“I warmly welcome Mr Pyne moving to update the law so that it is in line with modern values that trust and empower women to make decisions about their own bodies,” she said.

“Nearly a third of women will seek an abortion over their lifetime and they must not be made to feel like criminals for making their own decisions about their own bodies.

“It is deeply disappointing that the big parties have done nothing to get rid of these antiquated criminal laws that are completely out of touch with the community.

“Abortion should be decriminalised, and more than that, it should be safe, it should be legal and it should be affordable.”

Waters called on the Labor government to support Pyne’s bill and for the conservative Liberal National opposition to allow a conscience vote.