Best Buy Geek Squad agent Josh Sorensen replaces a motherboard on a laptop at Geek Squad City in Brooks, Ky., in 2012. A child pornography case launched at the facility led to the discovery that eight Geek Squad technicians had served as paid informants for the FBI. (Ken James/Bloomberg News)

A federal judge in California this week threw out nearly all the evidence in a child pornography case, but rejected a key defense argument — which had the potential to impact many more cases around the country — that the investigation was tainted because it had started with a discovery made by a Best Buy “Geek Squad” technician.

The case against Mark Rettenmaier had gained national attention after the defense contended that technicians at a giant Best Buy computer repair facility in Kentucky were working so closely with federal investigators handling child pornography cases that they should be considered government agents — and therefore need search warrants. However, U.S. District Judge Cormac J. Carney on Monday found that Rettenmaier had given up his right to privacy by consenting both orally and in writing to the search of his hard drive.

Carney did find fault with the government’s case against Rettenmaier, though, ruling that searches of his home and cellphone were illegal because an FBI affidavit for a search warrant misstated key facts about the case. While only one of the questionable images found on Rettenmaier’s hard drive ended up as part of the criminal case, the search of his home and phone produced thousands of alleged child pornography pictures, according to federal court records.

But Carney said the image found in Kentucky was not pornographic, that the FBI did not disclose that image was found in “unallocated space” on Rettenmaier’s hard drive, and that the FBI misstated how many times they searched the hard drive before applying for a warrant, according to Rettenmaier’s lawyer, James D. Riddet.

The ruling deals a possibly fatal blow to the prosecution of the five-year-old case. Federal prosecutors in Los Angeles declined to say whether they planned to appeal. Riddet said if the government appealed, he would cross-appeal and re-raise the issue of Best Buy’s seemingly close relationship with the FBI. Riddet filed hundreds of pages of exhibits showing that eight different Geek Squad City employees were paid by the FBI over a six-year span, as well as emails that detailed the government’s use of Geek Squad technicians as “confidential human sources.”

Carney did not issue a written ruling in the case and did not indicate whether he planned to do so, Riddet said.  Thom Mrozek, a spokesman for the U.S. attorney’s office in Los Angeles, said Tuesday, “We are awaiting a written ruling from the court, and will consider our options after reviewing that order. In the meantime, we will continue to investigate the case.”

Best Buy has repeatedly denied any inappropriate actions by its employees or ties to the FBI. In a statement to The Post Tuesday, Best Buy reiterated that its Geek Squad employees inadvertently discover what appears to be child pornography about 100 times a year, and that they are legally obligated to report it. “To be clear,” Best Buy’s statement said, “Geek Squad does not work for the FBI and never has.”

The case attracted the attention of civil liberties experts who feared that the Geek Squad had grown into a proactive arm of the government, snooping on citizens without the requirement of judicial oversight. Riddet characterized the relationship between the FBI and Geek Squad City as “a joint venture to ferret out child porn,” noted that Best Buy’s management had been made “aware that its supervisory personnel were being paid by the FBI,” and that the repair facility’s “data recovery system was designed to identify and report child porn from all over the country.”

Prosecutors acknowledged in March that the FBI’s payments to Geek Squad employees “muddied the waters” of the relationship, but that “did nothing to turn Geek Squad City supervisors into government agents or Geek Squad City itself into a secret FBI surveillance machine.” The government claimed in its response brief that “No FBI agent ever asked, instructed or directed any employee at Geek Squad City, including those designated as CHS’s [confidential human sources], to search for child pornography or evidence of any other crime on behalf of the FBI, at any time.”

The case began in November 2011 when Rettenmaier, a gynecologic oncologist, took his desktop computer to a Best Buy in Mission Viejo, Calif., because it wouldn’t boot up. The technicians there were able to fix that problem, but not recover Rettenmaier’s data. Court records show that Best Buy sends all of its data recovery jobs to Geek Squad City in Brooks, Ky., outside of Louisville.

The records also show that Rettenmaier signed a form when he first handed over the computer, stating that any child pornography found by Geek Squad technicians will be reported to the authorities. When a technician called Rettenmaier to ask him if he wanted his data restored, including pictures, Rettenmaier said yes on a recorded call. In general, searches performed by private entities do not require a search warrant — only government searches do.

Court records show that in the course of recovering Rettenmaier’s data, a Geek Squad technician found “multiple inappropriate images,” including a photo of a naked girl, believed to be 9 years old, in the “unallocated space” on Rettenmaier’s hard drive. Unallocated space is where deleted data resides on a computer until it is overwritten by other data, but it often does not have metadata such as when it was created, accessed or deleted, and because it lacks that information courts have ruled that photos found in unallocated space cannot be proved to be “possessed” by the computer’s owner without other evidence.

Riddet argued that the fact that Geek Squad technicians were exploring Rettenmaier’s “unallocated space” was evidence they were going beyond standard data recovery in an attempt to assist the FBI. Carney rejected that argument. The technician testified that he was simply trying to recover all of the customer’s photos, wherever they might be.

But Riddet also argued that the FBI then improperly represented the photo and how it was found in an affidavit for a search warrant for Rettenmaier’s home and other computers in California. After the Geek Squad alerted the FBI in Louisville about “another one out of California” in December 2011, court records show an agent visited Geek Squad City in January 2012 and saw the image, which authorities say is part of a known series of pornographic photos, but is not itself explicit. The agent seized Rettenmaier’s hard drive but was unable to access it because it was in the unallocated space. She returned to Geek Squad City, which showed her how to locate the image, and agents then did so. Riddet argued that was an unauthorized search, and that when agents in California applied for a warrant for Rettenmaier’s home, they did not disclose that the image itself was not explicit and that it was found in unallocated space.

Carney cited those omissions in granting Riddet’s motion to suppress the search, Riddet said. But the judge denied the suppression motion based on an inappropriate relationship between the FBI and the Geek Squad, instead focusing on Rettenmaier’s consent to the private search of his computer in Kentucky, according to Riddet. Mrozek confirmed Riddet’s account of the ruling.

“I felt that it was a very well-reasoned, well-thought out ruling,” Riddet said, “which was consistent with what we argued. I agree wholeheartedly with what Judge Carney did suppressing the search of the residence.” He said the trial of the case, scheduled for next month, has been postponed to next year.