Australia's High Court has backed migrant claims of unfair laws, in a ruling that has far-reaching implications for asylum policy.
Two Sri Lankan men held offshore on Christmas Island had argued that laws barring them from appeal in Australian courts were unfair.
The court ruled unanimously that they had been denied "procedural fairness".
The ruling could force the government to review its policy of offshore processing for asylum seekers.
Successive governments have held refugee claimants in offshore detention - on Christmas Island and before that in Nauru - and barred access to appeal if their claims for asylum were denied.
Lawyers for the migrants argued that this placed the decisions of immigration officials - under whose authority the asylum-seekers are assessed - above the law.
The issue is highly toxic for the minority government of Prime Minister Julia Gillard, who had made election promises to discourage new refugee inflows to the country.
The legal dispute hinged on the distinction made by the government since 2001 between asylum-seekers who arrive by plane and those who come by ship.
Boat arrivals are placed in detention; their status is assessed by contractors of the Immigration Department and if denied, they have had - until now - no right of appeal in Australia's courts.
But those who arrive by plane are not automatically detained - and do have the right of appeal if their claim to refugee status is denied.
The seven judges of the High Court of Australia were unanimous in their ruling.
They said the two Sri Lankan Tamil men - who arrived in October 2009 and are known simply as M61 and M69 - were denied "procedural fairness".
Attorney-General Robert McClelland said the judgement could force a change to current laws and policies, and would need to be examined carefully.
Immigration Minister Chris Bowen said the judgement had "significant ramifications".
"It needs to be worked through in a methodical and calm manner, which is what I'll be doing in coming weeks and making recommendations to my Cabinet colleagues," he said.
One of the lawyers for the two men, David Manne, praised "a great decision for the rule of law in this country".
"The attempt to keep these people outside Australian law and the protection of Australian courts has failed," he said.
"So we call on the Government to publicly confirm that it will respect the court's decision and give all these people a new decision-making process that complies with the ruling of the court."
Ms Gillard's minority government relies on support from the Green Party to stay in power; the Greens have long been critical of the harsh immigration laws.
But many Australians dislike the prospect of more asylum-seekers arriving in the country.
The conservative opposition, meanwhile, has said it wants much stronger laws, and has warned that this court ruling could mean that the legal system will become clogged by appeal cases for years to come.