Federal Court judge Jeffrey Spender also warned that governments should not consider themselves above the rule of law in matters involving national security.
In the latest instalment in a saga that has already embarrassed the Government, police and the Commonwealth Director of Public Prosecutions, Justice Spender found that Mr Andrews was wrong to withdraw Dr Haneef's visa on character grounds.
A furious Mr Andrews ordered an appeal against Justice Spender's decision that Dr Haneef's visa should be reinstated. "I acted in the national interest and I acted for the national security of Australians. I make no apology about that whatsoever," he said.
He flatly rejected the judge's finding that he had used the wrong test to cancel Dr Haneef's visa and dismissed calls for his resignation. He was backed last night by Prime Minister John Howard, who said Mr Andrews' decision was correct.
Mr Andrews said the Federal Government had correctly relied on a legal precedent to cancel Dr Haneef's visa on character grounds, and said he still harboured unspecified suspicions about Dr Haneef, which had increased following "further information" he had received since revoking the visa.
"Justice Spender is wrong in his interpretation of the legislation," he said. "There still is in my mind a reasonable suspicion as required by the migration legislation in relation to Dr Haneef."
Dr Haneef's lawyer, Peter Russo, said the ruling was a "big step to victory" in the battle to have visa reinstated.
He said Dr Haneef, who had been working at the Gold Coast Hospital before he was arrested on suspicion of links to failed terror plots in London and Glasgow, was "gratified" by the decision.
In Bangalore, Dr Haneef's cousin Imran Siddiqui, said the family was pleased, but that it was "too early to celebrate".
"We would have been happier if Andrews had taken everything into consideration — the fact that all charges against Haneef were dropped and that even the Director of Public Prosecutions felt there was no case against him, and now this verdict — and just decided to give his visa back," Mr Siddiqui said.
Following the ruling, the Government won a 21-day stay on the decision that would have forced it to return the visa.
"There is no room for the view … that the executive should have exclusive responsibility over all matters involving national security," Justice Spender said. He said the executive was "charged with a heavy responsibility in matters of national security, but Parliament has defined the limits … and it is for the judicial arm of government to ensure that ministerial or other official action is lawful".
Mr Andrews was assailed by criticism from across the legal and human rights spectrum after the decision, but he was supported by prominent criminal lawyer and former head of the Australian Crime Commission, Mr Peter Faris, QC.
Mr Faris said yesterday's decision was "reached on highly technical grounds and is highly artificial". He anticipated it would be overturned on appeal.
"It's not a victory for anything," he said. "Australia must have an absolute right to determine arbitrarily who it permits to come into the country and who gets to stay. We can't spend all our time litigating the decision."
But human rights lawyer Greg Barns said the case "knocks on the head this absurd view that a lot of conservative commentators have, that when it comes to matters of national security, the courts ought to defer to governments." Liberty Victoria past president Brian Walters, SC, said the decision was "a humiliation for Kevin Andrews and the entire Government", and said Mr Andrews deserved to be sacked.
Justice Spender's finding rested heavily on the use and meaning of the word "association". When Mr Andrews cancelled Dr Haneef's visa, he contended the doctor was of bad character because of his association with two of the suspects in the failed UK car bombings, his second cousins Sabeel and Kafeel Ahmed.
But the judge said that Mr Andrews' definition was so wide it would include relationships that were "utterly remote" from the alleged criminality. This could include family relationships, professional associations, or even "the battered wife scenario" causing a person to fail the character test.
However, Justice Spender conceded that Mr Andrews would have been right to cancel the visa if he had done so on the basis that the Indian doctor had been named as a person of interest by the British police and had been charged in Australia.
"These matters would have permitted the minister to conclude that the association between Dr Haneef and the Ahmed brothers went beyond a purely familial, social, innocent relationship," he said.
Justice Spender said Mr Andrews presented the public with selected highlights of confidential police evidence, but failing to give the court the same evidence.
"There is … a certain piquancy in the present case," he wrote. "The minister has chosen to give a selected part of what is said to be protected information to the public by way of press release, but has not sought to divulge to the court any part of the protected information."
Opposition's immigration spokesman Tony Burke called for a judicial inquiry into the Government's handling of the Haneef affair, claiming the saga may have challenged community support for Australia's immigration and anti-terrorism laws.