A former Bowdoinham man who downloaded sexually explicit images and videos of children while at his parents’ house in Oakland in 2012 was sentenced Friday in U.S. District Court in Bangor to serve nearly five years in prison.

Daniel Lajoie Jr., 46, who later lived in Oakland, pleaded guilty before Judge John A. Woodcock Jr. last Oct. 8 to a charge of possession of child pornography.

Woodcock sentenced Lajoie to serve 57 months in federal prison to be followed by five years of supervised release.

Agents from the Department of Homeland Security began investigating Lajoie after they suspected he was sharing sexually explicit videos of children online, according to an affidavit filed with the court by a Homeland Security agent Monday.

Authorities first executed a search warrant on Aug. 22, 2012, at the home of Lajoie’s parents in Oakland, where his father told them that his son frequently visited and brought his laptop computer with him. Agents on the same day went to Lajoie’s home in Randolph, Loren Thresher of Homeland Securities Investigations said in the affidavit.

During questioning, Lajoie admitted that he downloaded child pornography on his laptop while at his parents’ house and allowed agents to examine his computer, revealing 50 images and 110 videos of child pornography, Thresher said.

Lajoie has remained in federal custody since his arrest last April 24.