The Court of Appeal has ruled it would be unlawful to further detain an Iranian overstayer without charge.
Thomas Yadegary was jailed after refusing to sign passport documents which would force his return to Iran.
He spent 30 months in Mt Eden prison before he was released on bail in April last year. In September, the High Court ruled it was unreasonable for him to be held for so long without charge.
The Court of Appeal has upheld that judgment.
Mr Yadegary destroyed his passport when he arrived in New Zealand and can't be deported to Iran without one.
He says he will be persecuted for converting from Islam to Catholicism if he is sent home.
In the meantime, Mr Yadegary lives in New Zealand illegally, but cannot be detained.
His refugee claims have been declined three times by the Refugee Status Appeals authority, and his case has also been unsuccessfully reviewed by the United Nations Refugee Agency UNHCR.
But Amnesty International says he should be allowed to stay in New Zealand.
The Department of Labour now has 20 working days to decide whether it will apply for leave to appeal.