Twelve teenage offenders locked up in Victoria's most notorious adult prison must be removed by the end of the week after a court confirmed they should never have been put there in the first place.
The state government has been ordered to transfer the juvenile offenders to a remand centre or a youth justice centre by Friday afternoon.
Up to 40 teen offenders were moved to Barwon Prison after juvenile detention centres were damaged in riots in November.
The Victorian Court of Appeal on Wednesday upheld a Supreme Court ruling that keeping juvenile offenders in an adult prison is unlawful.
Supreme Court Justice Greg Garde last week ordered the youths be immediately transferred out of the Grevillea unit of Barwon Prison, which had not been lawfully established as a youth remand centre.
Lawyers for the youths said the offenders - all of whom are on remand - were being kept in appalling conditions.
A stay was put on the order when the government indicated it would appeal the finding - and that it had nowhere else for the teens to go.
It will take the government 48 hours to transfer them to a more suitable juvenile detention centre, the appeal court heard on Wednesday.
Appeal Court President Marilyn Warren said it would be reasonable to expect "all stops would be pulled out" by the government.
"This court expresses no view about the merits of the decision made by the minister to establish a detention centre at Barwon Prison," the court said.
"That is a matter of policy for government."
The role of the court is to ensure the government acts according to law, the ruling said.
In this case it did not.
Bryan Walters QC said the fact the orders were made a week ago and had not been complied with was unseemly.
"Particularly given the message it sends (the youth offenders) with regards to compliance with the law," he said.
Police Minister Lisa Neville said the decision to house the young people from Parkville at Barwon was not taken lightly but a result of their behaviour.
"Not just at Parkville where they destroyed 60 beds, but also their behaviour in the community, which has been very serious and left huge scars and trauma in our community," she said.