Australia's top court has ruled that the government's power to hold a person indefinitely in immigration detention is unlawful.
The landmark ruling overturns a 20-year-old precedent that has shaped Australia's border policies.
It could trigger the release of 92 people in immigration detention who cannot return to their home countries, the government says.
The solicitor general warned it would prompt a wave of compensation claims.
The case, heard before the High Court of Australia on Wednesday, involved a stateless Rohingya man - known by the pseudonym NZYQ - who faced the prospect of lifelong detention because no country would resettle him due to a criminal conviction for child sexual offences.
The government had argued that his detention was lawful as they intended to remove him from the country - despite their inability to do so.
The result overturns a 2004 case known as Al-Kateb v Godwin, which has faced several legal challenges over the years.
In that verdict, the High Court had found that indefinite detention was lawful, as long as the government had the intention of eventually removing that person from Australia.
But in many cases, those facing deportation have argued they are stateless as they have nowhere to safely return, and no resettlement options.
The result has been lengthy detention stays for some asylum seekers caught in Australia's system.
According to the Human Rights Law Centre (HRLC), the Australian government holds people in immigration detention for 708 days on average and there are currently 124 people who have been in detention for over five years - while historically, some cases have spanned more than a decade.
In NZYQ's case, the court heard that several countries - including the UK, New Zealand, Canada, and the US - had refused to take him in, but the government maintained that a US resettlement was still possible.
The HRLC's legal director Sanmati Verma said Wednesday's ruling would have "life-changing consequences for people who have been detained for years without knowing when, or even if, they will ever be released".
In court, the government said it had identified 92 people currently in immigration detention under similar circumstances to NZYQ.
Of those, nine are stateless, while most of the others cannot be returned home for fear of persecution. The court heard many of them were not being released on character grounds, with a few on the grounds of national security.
Ahead of the ruling, Australia's solicitor general Stephen Donaghue warned that overturning Al-Kateb would trigger their release, and that "the consequence [would] be indefensible damages claims".