The opposition along with minor parties and independent lawmakers passed a bill that would give sick asylum seekers easier access to mainland hospitals.
Australia's government suffered an embarrassing defeat in Parliament on Tuesday, as the lower house voted for a measure allowing asylum seekers to access medical care, the first such loss by a government in 78 years.
Independent lawmakers and the opposition Labor party voted together to pass the bill by 75 votes to 74, dealing a blow to the ruling conservative coalition, which is trailing heavily in polls ahead of an election due in May.
"Great to see the Australian parliament finally vote for humanity," Behrouz Boochani, an Iranian refugee held in an Australian-run camp in Papua New Guinea (PNG) wrote on Twitter, hailing the passing of the legislation.
"Many people are happy now because they will finally receive medical treatment," Boochani.
'A historic moment for all of the refugees'
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 government lost its lower-house majority at a by-election in October.
"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.
"Where we will always stand, and the Australian people can always trust us to do, is to have the mettle to ensure the integrity of our border protection framework."
Immigration policy requires asylum seekers intercepted at sea to be sent to camps in PNG and its northern island of Nauru, and they cannot set foot in Australia, even if they are found to be refugees.
Opponents of the policy introduced the measure to amend the Migration Act to allow the temporary transfer of "transitory persons" from PNG or Nauru to Australia for medical assessment, a move backed by doctors.
The United Nations has repeatedly criticised Australia over conditions in the camps, where it says detainees lack adequate medical and mental health care.
Morrison and his government staunchly opposed the bill, saying care available at the detention camps was adequate and the bill could open a loophole for asylum-seekers to exploit.
"It's a historic moment for all of the refugees on Manus and Nauru," Boochani added.