A Portland man who initially tried to blame hackers and his girlfriend’s son after federal agents say they caught him in April downloading child pornography pleaded guilty Tuesday to a federal possession charge.

William Alfred Roscoe, 29, of 5 Montgomery St., appeared before Judge Jon Levy in U.S. District Court in Portland and waived his right to have the case against him presented to a federal grand jury as part of a plea agreement in which a charge of attempted receipt of child pornography was dismissed.

Federal agents began investigating in March after discovering someone was downloading child pornography in the multi-unit apartment building at the intersection of Montgomery and Congress streets in Portland. But their initial investigation led them to execute search warrants at the incorrect apartments on March 13 and April 17, according to an affidavit filed with the court by Agent David Fife of the Department of Homeland Security seeking a warrant for Roscoe’s arrest.

While investigators were in the building on April 17, they knocked on doors to interview tenants, leading them to contact Roscoe’s girlfriend at her place of work. She came to the apartment to let investigators in, they spoke with her and Roscoe, and she gave them permission to inspect a laptop computer that contained “large quantities of child pornography,” Fife wrote in the affidavit.

“During our brief interaction, Mr. Roscoe repeatedly speculated that someone had either hacked into the computer to view child pornography there, had broken into the apartment and accessed the computer using a set of keys (his girlfriend) had recently lost, or that (his girlfriend’s) 13-year-old son had been looking at such things using the laptop,” Fife wrote.

Authorities obtained a search warrant on April 21 to examine the laptop, and Portland police Detective Eli Chase found 11 child pornography files that had been partially downloaded at the time the computer was seized, the affidavit says.

Roscoe has been held in federal custody since his arrest on April 30.

He is scheduled to be sentenced on the possession of child pornography charge on Oct. 7. He faces up to 20 years in prison and a fine of as much as $250,000.