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.
Earlier, Judge Kelly said it seemed the tennis star had obtained the necessary exemption to travel restrictions prior to his arrival in the country.
The government acknowledged in court that Djokovic was not given enough time to respond following the notification to cancel his visa.
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.
Djokovic court case: Could he argue his way in?
Is tennis saga an unforced error for Australia?
Why Djokovic is a polarising player
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.