The New Zealand prime minister has issued an apology to Megaupload boss Kim Dotcom.
He said sorry because a New Zealand law enforcement agency was judged to have illegally spied on Mr Dotcom.
The investigation was illegal because the agency can only spy on those with no right to reside in New Zealand. Mr Dotcom won that right in 2010.
The spying was carried out just before police raids that shut down file-storing service Megaupload.
Mr Dotcom's home and the offices of Megaupload were raided in January as part of an FBI investigation. It alleges that Mr Dotcom was head of a group of Megaupload employees that made millions from copyright piracy.
In June, a New Zealand court ruled that the search warrant used in the raids was illegal.
Prime Minister John Key apologised after an official report into the Government Communications Security Bureau (GCSB) surveillance of Mr Dotcom and his involvement with Megaupload.
The GCSB was asked to spy on Mr Dotcom by New Zealand police prior to the January raids.
The report was written by the Inspector General of Intelligence, the official overseer for New Zealand's spy agencies. It said the surveillance was illegal because Mr Dotcom, who was born in Germany, had achieved permanent residency status.
In a statement, Mr Key said: "I apologise to Mr Dotcom... We failed to provide that appropriate protection for him." The illegal surveillance was the result of "basic errors" said Mr Key.
"It is the GCSB's responsibility to act within the law, and it is hugely disappointing that in this case its actions fell outside the law," he added.
It is not clear what effect the Inspector General's report will have on US attempts to extradite Mr Dotcom to face charges in America. The extradition hearing is now scheduled for March 2013.
The apology came a day after Mr Dotcom revealed more details of his next project, a music-sharing service called Megabox.