Asylum seekers in offshore detention will get easier access to medical treatment in Australia after the government suffered a historic defeat.
Labor and the crossbenchers combined to win a series of 75-74 votes over the coalition government on a bill to give medical transfers to asylum seekers on Manus Island and Nauru.
The laws passed the lower house on Tuesday and look set to pass the Senate on Wednesday, before being given royal assent.
Prime Minister Scott Morrison is already promising "contingency" measures to ensure the new laws don't undermine Operation Sovereign Borders.
"The Labor Party have failed to learn their lessons of failure when they had responsibility for border protection in this country," an angry Mr Morrison told reporters on Tuesday night.
"The Australian people have looked at Bill Shorten today and they have found him weak, and he is."
But Opposition Leader Mr Shorten said borders can remain strong while the nation also looks after people in Australia's care.
"I believe we can keep our borders secure, we can uphold national security, but still treat people humanely," Mr Shorten told parliament.
Under the negotiated amendments, the Home Affairs minister will have 72 hours to make a decision on whether to agree to a medical transfer.
If the minister rejects for it medical reasons, that decision can be reviewed by a medical panel, who can recommend it goes ahead.
Then it's up the minister to reject it on medical grounds again, or national security grounds, or if the person has a substantial criminal record and poses a threat to the Australian community.
Home Affairs Minister Peter Dutton said the changes would start unravelling Australia's border protection policies put in place when the coalition won in 2013.
"I think there's no question that people smugglers will be hearing very clearly that the policy in Australia has changed," he told ABC's 7.30 program.
The doctors on the medical panel 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.
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 last time a government lost a vote on legislation on the floor of the house was in 1929, while in 1941 the government lost a vote on a budget bill. Both triggered snap elections.
But Mr Morrison said the next election will be in May, after the budget is handed down in April.