•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 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," Mr Wood said.
Judge Kelly appeared to agree with Mr Wood's argument and told government lawyers that he felt "agitated" by what he had heard so far.
"What more could this man have done?" he asked.
Djokovic's lawyers have also argued that his treatment by Australian Border Force officers after his arrival was "manifestly unjust".
After being approached by officials at the airport, he asked to wait until the morning to hear from his team before deciding whether to leave the country. This was initially agreed to by officials.
He then went to sleep, but was woken up around 06:00 by officers who allegedly pressured him to respond "because it was better for him if they made the decision right away".
Government lawyer Christopher Tran argued that Djokovic's recent Covid infection did not qualify him for an exemption from travel rules, and denied there was any unfairness or unreasonableness in the decision.