Chief High Court judge Helen Winkelmann yesterday ruled that search warrants used in the raid were invalid because they did not adequately describe the allegations against the internet multi-millionaire.
She said the warrants, issued by the District Court, gave police authority to seize too wide a range of items.
The United States claimed Dotcom and his associates were behind the world's biggest criminal copyright violation through Dotcom's file-sharing website Megaupload, which carried about 4 per cent of the world's internet traffic. The men deny the charges.
Dotcom's American lawyer, Ira Rothkin, told Radio New Zealand Judge Winkelmann's ruling was "incredibly embarrassing" for the United States and New Zealand governments, and a "tremendous blow" to the case against Dotcom.
"The government was engaged not only in wrongful conduct but in double wrongful conduct: they weren't allowed to go ahead and do the initial seizure of the hard drives in the way they did it and then after they got the hard drives they violated the law again by bringing them offshore when they weren't allowed to.
"It's particularly embarrassing when you consider that the United States has called this matter the largest copyright case in history and one would think that with such a large case that they would have a higher standard of care in how they conducted themselves."
Mr Rothkin said defence counsel would be making arguments to the court about what remedies Dotcom ought to receive.
"In terms of egregious behaviour this is at the high end of the scale of a wrongful intrusion on privacy."
Dotcom, who got a good reception at a ratepayers' meeting in Coatesville last night, has not spoken publicly about the ruling, but has taken to Twitter.
"Sweet!" He tweeted yesterday evening.
"New Zealand is beautiful. To all my followers abroad come visit NZ (but not if you run a cloud storage biz)," he said later.
Dotcom and Finn Batato, Mathias Ortmann and Bram van der Kolk were arrested in January after a request for assistance from the FBI.
The United States claimed the men were behind the world's biggest criminal copyright violation through Dotcom's file-sharing website Megaupload, which carried about 4 per cent of the world's internet traffic. The men deny the charges.
The ruling yesterday is the third embarrassment in the case for Crown lawyers, who are representing the United States in the arrest, seizure and extradition process.
It has previously emerged they used the wrong type of restraining order to seize Dotcom's funds and seizing his property without notice when he should have been given the chance to challenge the seizure.
Then it emerged the Crown knew it was using the wrong order while the raid was in progress.
During the raid, police seized computers, phones and anything which appeared to contain a hard drive - a total of 135 items.
Ms Winkelmann said the search warrant was too broad in the way it described what could be taken.
"These categories of items were defined in such a way that they would inevitably capture within them both relevant and irrelevant material. The police acted on this authorisation.
"The warrants could not authorise seizure of irrelevant material, and are therefore invalid."
She added: "The police relied on invalid warrants when they searched the properties and seized the various items. The search and seizure was therefore illegal."
She noted that even if she was wrong about the validity of the warrants, it was clear police had "exceeded what they could lawfully be authorised to do" because they continued to hold irrelevant material.
She said police faced difficulties executing the search warrants in a lawful manner because they were not the investigating officers with knowledge of the operation.
It emerged during the hearing this month that FBI staff copied some of the seized hard drives at the police electronic crime lab in South Auckland and sent the copies back to the US.
This prompted Dotcom's lawyer, Paul Davison, QC, to say cloning the hard drives had "subverted" his client's rights.
The four accused wanted a declaration the removal of the clones from New Zealand was unlawful.
They also wanted an independent lawyer to decide which of the items seized were relevant to the investigation.
Ms Winkelmann acknowledged the copies had been sent to the US without the consent of Dotcom and his associates, but would not go any further.
She said she wanted the Crown and Dotcom's lawyers to work out a solution before a hearing scheduled for July 4.
The police have previously defended the surprise raid which used helicopters and the special tactics group armed with automatic weapons.
Officials seized Dotcom's collection of more than 20 luxury cars, wife Mona's jewellery and expensive art works. More than $10 million held in New Zealand accounts was also seized.
Police said they were considering the judgment and were in discussions with Crown Law to determine what further action might be required.
Attorney-General Christopher Finlayson's office said he would not comment on matters before the court.
Simpson Grierson partner Greg Towers said last night the four men were "very happy" with the decision and were considering their remedies.