Australian MPs have passed a landmark bill with an opposition amendment making it easier for sick refugees held offshore to be treated in the country.
This is the first time in decades a government has lost a vote on its own legislation in the lower house.
The move is a blow for PM Scott Morrison’s minority government’s highly controversial immigration policy.
Since 2013, Australia has sent asylum seekers arriving by boat to detention centres on Nauru and Papua New Guinea.
Critics say it has harmed the welfare of detainees, including children.
Doctors have long warned of inadequate medical facilities on the islands, while the UN has previously described the camp conditions as “inhumane”.
However, Mr Morrison said: “There is no form of this bill that does not weaken our border protection.”
Australia has long defended its offshore detention policy by arguing that it stops deaths at sea and disrupts the trade of people smuggling.
The bill passed in the House of Representatives by one vote after the Labour opposition and crossbench MPs agreed on last-minute amendments.
It is expected to sail through the upper Senate later this week where it will become law.
So what does the bill allow?
Doctors will now have the power to recommended transfers for refugees on Nauru and Manus to Australia for treatment.
However, the immigration minister could ask an independent panel to review the medical assessment, and would have some authority to overrule it.
Previously, doctors had reported that their medical transfer recommendation were ignored by authorities.
Refugee lawyers thus had to apply for court orders to bring ill people to Australia. There were 44 medical transfers achieved through court battles.
Why was there a push for this law?
Last year, Australians were horrified by reports of a mental health crisis among children in detention. Doctors reported affected children too depressed to eat or sleep, and attempts of suicide among those as young as 11.
The wave of public backlash pushed the government to evacuate more than 100 children and their families from Nauru to Australia.
Advocates warned that a similar mental health crisis, and a plague of other medical issues, was also constant among the 1,000 adult detainees stuck on Nauru and Manus Island.
In one of several high-profile cases, an inquest in July found that the death of Iranian refugee Hamid Khazei on Manus Island from a foot infection could have been prevented if he had been transferred to Australia earlier for medical treatment.
How many sick asylum seekers are there?
The government had warned that the bill provided a “loophole” that would allow all of the remaining asylum seekers to reach Australia.
However, it declined to answer whether that meant all offshore detainees were seriously ill.
Medicins Sans Frontieres, which provided mental health treatment to Nauru detainees last year, has noted that depression and suicide ideation was widespread and directly caused by a policy of indefinite detention.
“Five years of indefinite limbo has led to a radical deterioration of their mental health and wellbeing,” said MSF Australia’s director, Paul McPhun.
In a public letter to MPs this week, Doctors4Refugees, an advocacy group of physicians, also identified dozens of sick refugee cases who had received inadequate treatment.
These included “life-threatening” heart conditions, kidney stones, tuberculosis and diseases common in the sub-tropical environment, such as malaria, dengue fever and chronic fungal infections.
Refugees on the islands had told the BBC they were pinning their hopes on the vote.