At the time of his arrest, Mr. Monsegur was serving as a foster parent for two young female cousins; his federal public defenders, Peggy Cross-Goldenberg and Philip L. Weinstein, said in court papers that their client’s decision to cooperate had not been a difficult one.

“His family came first,” the lawyers wrote. “He would do whatever he had to do to protect the girls and avoid their placement in the foster care system.”

Judge Preska noted that Mr. Monsegur and his family had been subjected to threats after his role as a cooperator became known in March 2012. As prosecutors have said in court papers, he had been vilified online by supporters of Anonymous and was repeatedly “approached on the street and threatened or menaced about his cooperation.”

The authorities were so concerned about his safety that they relocated Mr. Monsegur and certain members of his family, prosecutors have said. “He despairs when he thinks of what he put his family through,” Ms. Cross-Goldenberg said in court.

Mr. Monsegur, 30, who as a youth lived in the Jacob Riis housing project on the Lower East Side of Manhattan, pleaded guilty before Judge Preska in August 2011 to 12 counts of hacking conspiracy and other charges. He was released on bail, but his bail was revoked in May 2012 after he made “unauthorized online postings,” the government has said.

He served seven months in custody and was again released on bail in December 2012. While detained at the Metropolitan Correctional Center, he developed and taught a computer-skills course, Ms. Cross-Goldenberg told the judge.

In court, Mr. Monsegur told the judge that in the past three years, he had “gone through a lot of changes, learned a lot of lessons.”