Two New Zealand-born bikies facing deportation from Australia have won a long-running High Court battle.
The court has ruled that Immigration Minister Peter Dutton was wrong to cancel the visas of Rebels gang leader AJ Graham of Tasmania, and Mehaka Tepuia of Perth.
Graham, who has lived in Australia since 1976, has a substantial criminal record, including for assault.
Mr Tepuia has no criminal record and has lived in Australia since 2005.
They both lost their visas on character grounds as members of the Rebels gang, which authorities have labelled "one of Australia's highest criminal threats".
It ruled the law he used to keep secret the information he based his decisions on was invalid.
It said it prevented the courts from testing if he was overstepping his legal powers.
Mr Dutton and the federal government had issued warnings about what an adverse ruling would mean.
"The potential for serious criminals to be released back into society will be the outcome," Mr Dutton said in mid-August.
He made the claim when the government - fearing today's ruling would go against it - tried to push through urgent law changes to protect classified intelligence and police security assessments.
The amendment has been referred to a senate committee.
Mr Tepuia was released this afternoon but an hour later his lawyer told him his visa has again been revoked.
He told RNZ he is now with his family in Perth but expects to be detained again.
Shortly after the court ruling came out, Graham's visa was cancelled for a third time by Mr Dutton, just as Graham prepared to walk free from Villawood Detention Centre in Sydney.
Last year, when a Federal Court overturned Graham's visa cancellation, Mr Dutton cancelled it again within hours and he remained locked up.
Today's ruling by a majority of the High Court said the practical impact of the law "amounted to a substantial curtailment of the capacity of a court ... to discern and declare whether or not the legal limits of power conferred on the Minister by the Act have been observed".
Mr Dutton had warned an adverse ruling could lead to 15 criminals and at least one jailed terrorist being freed, and would undermine public confidence in the entire migration framework.
The power to cancel visas has been central in Mr Dutton's crackdown on motorcycle gangs - many of whom are New Zealand citizens.
Since these powers were strengthened in late 2014, more than 2600 visas have been cancelled, including 140 related to organised crime figures.