The vote drew cheers from asylum-seeker activists in parliament's public gallery but the upper house must approve the bill before it becomes law, so the defeat, though damaging for the government, does not trigger an immediate election.
The final vote, shortly after 6pm on Thursday, delivered a stunning victory for Labor, the Greens and crossbench MPs to enforce new rules to give doctors more say over the transfer of refugees from Manus Island and Nauru for treatment in Australia.
Morrison said he would repeal the "foolish law" if his government were re-elected.
Labor has handed the Coalition a campaign gift, and the Liberal Party will be quickly dusting off their tried and tested campaign material on boat arrivals and erecting billboards in marginal seats across the country.
A dozen refugees have already died in the Manus and Nauru camps and a number have attempted suicide, including children.
The bill must be approved by the upper house to become law, but is likely to pass, as the Senate supported an earlier version past year.
"My job now is to do everything within my power, and the power of the government, to ensure that what the Parliament has done to weaken our borders does not result in boats coming to Australia", he said.
'Under Labor's law, a person who has been convicted of serious offences would have to come to Australia and there is nothing the minister could do to stop it, ' he said.
"I believe that we can keep our borders secure, we can uphold national security but still treat people humanely", Shorten told Parliament.
The changes included a provision that only the 1,000 asylum seekers now held on Nauru and Papua New Guinea and not any future arrivals would be considered for medical evacuation under the new regime.
"Votes will come and they will go, they do not trouble me", Prime Minister Scott Morrison told a news conference in the capital, Canberra, after the vote.
"Today Labor will fight for more jail time and increased penalties for banks and bankers who do the wrong thing", Opposition Leader Bill Shorten said.
But criticism of the camps has grown amid reports of abuse, suicides and lengthy detention periods, even as the government says the policy is discouraging asylum seekers from embarking on risky sea voyages.
Major changes to Australia's health system would be led by a new, independent expert commission under a federal Labor government, making reforms harder to unpick.
"There is no question that people smugglers will be hearing very clearly that the policy in Australia has changed", Dutton said.