Proposed new laws making it easier for asylum seekers to get medical treatment have passed parliament despite the government's opposition.
The coalition tried to derail the Labor amendments at the last minute with advice from the solicitor-general arguing the laws were unconstitutional.
But Labor changed their proposed laws to explicitly say a panel of doctors judging medical transfers would not be paid, getting around the constitutional issue.
The amendments were originally made in the Senate, and under the constitution the Senate is not allowed to make bills increasing the spending of public money.
The laws now go back to Senate where they are expected to be approved.
Despite heavy pressure from the government, six crossbench MPs sided with Labor to inflict a series of defeats on the coalition on the floor of the lower house.
"I believe we can keep our borders secure, we can uphold national security, but still treat people humanely," Labor leader Bill Shorten told parliament on Tuesday.
An angry Prime Minister Scott Morrison told Mr Shorten Labor was trying to "kid themselves" that the changes were being made in the name of humanitarianism.
"I remind them that their humanitarianism, as supposed, last time led to child deaths, it led to the total destruction of our borders and it took the strength again of a coalition government," he yelled across the chamber.
"The people of Australia will remember this day and know that this is now on your head - leader of the opposition."
Under the negotiated amendments, a medical panel of two doctors would assess requests for medical transfers from Manus Island and Nauru.
The Home Affairs minister would have 72 hours to make a decision on whether to agree to a medical transfer.
The minister will only be able to reject the transfer on national security grounds or if the person has a substantial criminal record and poses a threat to the Australian community.
The doctors were due to be paid under the original proposal - but Labor's late change to exclude remuneration means the bill cannot be rejected on constitutional grounds.
Solicitor-general Stephen Donaghue QC argued the amendments could breach the constitution because of the payment issue, but ultimately it was up to parliament to decide if they did or not.
With the constitutional issue no longer relevant, the coalition avoided a potentially disastrous defeat on an appropriation bill.
Australian Associated Press