Australia's conservative minority government suffered a monumental political defeat on Tuesday, becoming the first administration in almost a century to lose a vote on major legislation and fuelling calls for a snap election.
Earlier, Attorney General Christian Porter warned the proposed bill was unconstitutional, as it was a spending bill originating in the Senate, after Labor amended the laws to explicitly say the panel of doctors judging medical transfers would not be paid.
Proposed changes to Australia's border protection laws have been declared "unconstitutional".
Despite the setback, the prime minister, Scott Morrison, remained resolutely on the political offensive, declaring the vote demonstrated Labor had failed to learn the lessons from of the past.
The legislation will not become law until it again passes through the Senate, most likely tomorrow, and when it is agreed by the Governor General.
Morrison said contingency plans had been put into place to manage the "risks" to the regime that Shorten and the crossbench had created, and the home affairs minister was already meeting with border command. "My job now is to work with our border protection and security agencies to do everything in my power to mitigate the damaging impact of what Labor have done tonight".
Opposite Leader bill Shorten.
"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.
If the motion fails, Labor will go to the election banging the drum that the Coalition has gone soft on banks.
'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'.
The bill gives doctors a greater say on the medical transfer of asylum seekers has had the support of Labor and most crossbenchers.
These widen the grounds on which a minister could refuse a transfer to cover those with a substantial criminal record, allow the minister up to 72 hours (instead of 24) for making a decision on transfers, and confine the application of the legislation to the present cohort of refugees and asylum seekers.
He is now the prime minister who has lost control of Australia's parliament.
Independent Kerryn Phelps's amendments would mean any two doctors could request a medical transfer for those in offshore detention.
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.