Novak Djokovic has won an appeal against deportation from Australia, with a judge ordering that he be released from hotel quarantine within 30 minutes.
Border officials previously said the tennis star did not meet the criteria for an exemption to the rule that non-Australians are fully vaccinated against COVID.
Djokovic had spent four nights in an immigration detention hotel before Monday morning’s hearing.
Djokovic latest: Star wins deportation case as Farage and Andy Murray row on Twitter
Judge Anthony Kelly noted that Djokovic had provided officials with a medical exemption given to him by Tennis Australia and two medical panels.
“The point I’m somewhat agitated about is what more could this man have done?” Mr Kelly asked Djokovic’s lawyer.
The judge quashed the decision to cancel his visa, saying it was “unreasonable” and the player hadn’t been given enough time to respond after he was notified of his visa cancellation.
Djokovic told border officials he was unvaccinated and had been infected with COVID twice, according to a transcript of an interview revealed in court.
The player has never publicly revealed his vaccination status.
Melbourne airport officials also made him switch off his phone from midnight to around 7.42 am, when the decision to cancel his visa was made, the judge said.
A group of around 50 supporters, many draped in the Serbian flag, celebrated outside the Melbourne court.
However, it may not be the end of the row.
Sky reporter Nicole Johnston, outside the hotel, said the case may now go back to the immigration minister and the department for home affairs to decide whether to reinstate the visa.
“Essentially the court found there was a failure in due process – that it wasn’t fair – so for now we wait to hear from the federal government,” said Johnston.
The Australian Open begins on 17 January, with the Serbian star bidding to become the most successful men’s player ever.
Analysis: Case a 'career-defining moment'
By Tom Parmenter, sports correspondent
One week before the start of the Australian Open and it’s hard to remember a more shambolic situation.
This extraordinary legal fight is a career-defining moment for Djokovic, who grew up in Serbia during the conflict in the Balkans.
He would practise his tennis in an empty swimming pool and occasionally run for cover when bombing raids started.
“It made us more hungry, more hungry for the success,” he has previously said.
If he is to come back from this, and maybe even win one more Australian Open, it would make him the most successful man ever to play the game.
There are many elite athletes who would have recoiled at the sight of the cramped room at the quarantine hotel, turned their nose up at the ropey food on offer and skulked back to their home country on the first plane available.
Novak though has stuck it out because he believes he has been wronged.
He is one of the most determined characters tennis has ever seen and whatever you think of him Djokovic is never easily beaten.
He has proved so many times – both on the court and now in the courts of Australia – it’s not over until it’s over.
Djokovic’s lawyers said the player should have been allowed to enter because he had recently had COVID and “was entitled to a medical exemption in accordance with Australian government rules”.
They filed papers that showed he tested positive last month and recovered.
They also showed the 34-year-old had received a letter from Tennis Australia’s chief medical officer on 30 December stating that he had been given an exemption on these grounds.
It said Djokovic’s first positive test was on 16 December and, on the date of issue, he “had not had a fever or respiratory symptoms in the past 72 hours”.
Photos have emerged in the last few days of the world number one – without a mask – with young players the day after he’s said to have tested positive.
It is not clear if Djokovic knew the results of his test at the time.
On the day he tested positive – 16 December – he was also presented with a stamp by the Serbian postal service in Belgrade, an event he tweeted about the next day.
In the next tweet, on 4 January, he said he was on his way “Down Under with an exemption permission”.
Djokovic has not disclosed his vaccination status, but has previously said he wouldn’t want to be compelled to get a jab to travel or play in competitions.
His case has polarised opinions, especially in Australia where he has won the tournament nine times.
Djokovic’s case has caused a political row after Prime Minister Scott Morrison said “rules are rules” and any passenger was responsible for meeting border regulations.
He was accused of taking advantage of the case to improve his popularity ahead of elections.
After narrowly missing out on a calendar grand slam in 2021, Djokovic will be keen to try to go one ahead of Rafael Nadal and Roger Federer as the winner of the most majors.
But the past few days have been far from ideal preparation, with his lawyers saying he was sleep-deprived and pressured by Australian officials to cancel his visa.
He is also said to have been temporarily unable to access the gluten-free meals and exercise equipment he requested.