The judge hearing Novak Djokovic's challenge to an order by the Australian government revoking his entry visa has dramatically overturned the decision.
Judge Anthony Kelly ordered the release of the tennis star from detention, and told the government to pay his costs.
The 34-year-old Serbian player flew into Melbourne last week, hoping to defend his Australian Open title.
But Immigration Minister Alex Hawke could still cancel his visa on new grounds.
The government acknowledged in court that Djokovic was not given enough time to respond following the notification to cancel his visa.
The player was told he would have until 08:30 local time last Thursday to make comments about the visa cancellation under section 116 of the Australian Migration Act, but the Border Force made the final decision shortly after 07:40.
The Judge said Djokovic could have had more time to make a submission about why his visa should not be withdrawn if authorities had stuck to the original time.
"We all play by the same rules," Judge Kelly said. "Stated in other terms: those rules were not observed."
The trial began on Monday morning after delays caused by technical issues with a live stream of proceedings.
Lawyers for Djokovic argued that the 20-time Grand Slam winner entered the country on the understanding that his exemption from restrictions requiring travellers to be fully vaccinated against Covid-19 was valid.
Nick Wood told the court that the exemption had been granted to the player by two separate medical boards following a recent coronavirus infection and that he had presented all the necessary medical evidence to officials.
"He had done absolutely everything. He had engaged with everything that was required of him by Tennis Australia," Wood said.