The Australian parliament has approved changes to immigration laws that include reintroducing controversial temporary visas for refugees.
The bill will allow refugees to live and work in Australia for three to five years, but denies them permanent protection.
It was passed by 34 votes to 32 in the senate and later backed by MPs.
Australia currently detains all asylum seekers who arrive by boat, holding them in offshore processing camps.
It says that those found to be refugees will not be permanently resettled in Australia, under tough new policies aimed at ending the flow of boats.
It also has a backlog of cases - about 30,000 - relating to asylum seekers who arrived before the current policies were put in place. Those people live in detention camps or in the community under bridging visas that do not allow them to work.
To secure enough support in parliament to pass the bill, the government made concessions. Children will be freed from detention on Christmas Island, an offshore camp where conditions have been strongly criticised.
The number of confirmed refugees Australia will agree to accommodate will rise by 7,500, from the current level of 13,750, by 2018 (reversing an earlier cut). Asylum seekers on bridging visas will be allowed to work while their claims for refugee status are processed.
The bill was narrowly approved in the senate after intense debate in a late-night sitting. It was then passed into law by the House of Representatives, where the government has a majority.
Prime Minister Tony Abbott described the move as "a win for Australia".
"We always said that three things were necessary to stop the boats - offshore processing, turning boats around and temporary protection visas, and last night the final piece of policy was put in place," he said.
Temporary visas were originally introduced under former Prime Minister John Howard but were criticised by rights groups and the UN for failing to meet Australia's obligations as a signatory to UN Refugee Conventions.
While refugees can live and work for a temporary period in Australia, the government can deport them to their country of origin after this period if it deems conditions there have improved.
Serious concern
The government won the vote in the senate - where it does not have a majority - with the support of the Palmer United Party (PUP) which had negotiated several changes, including the provision relating to children detained on Christmas Island.
Rights advocates and other experts have voiced serious concern about the effects of life in limbo in cramped detention conditions on children of all ages.
PUP leader Clive Palmer called the move the best option available.
"It's all very well for people to shake their head, but they're not locked up on Christmas Island," he told reporters.
But refugee advocates said the move was a "shattering blow for asylum seekers who face the grave risk of being returned to danger".
Unless current migration visa rules were changed, many of those identified as refugees would find themselves with "no pathway to permanent protection", said Paul Power, chief executive of the Refugee Council of Australia.
He welcomed the "long overdue" decision to release children from detention, but condemned their use by the government "as a bargaining chip for a destructive legislative package to seriously weaken refugee protection".
Opposition leaders had also accused the government of using asylum seekers as political pawns.
Speaking before the senate vote, senior Labor figure Tony Burke said Immigration Minister Scott Morrison was "effectively wanting to use people as hostages".
"He could have started processing [asylum seekers]. He chose to not do the processing, and is now saying unless we vote for his measures, then he'll continue to keep people in detention," he told ABC Radio.