But the office of Joon H. Kim, the acting United States attorney in Manhattan, said in a memorandum to Judge Denise L. Cote that although Mr. Weiner’s “self-destructive path from United States congressman to felon is indisputably sad, his crime is serious and his demonstrated need for deterrence is real.”

In Mr. Weiner’s plea agreement, prosecutors had said a sentence within the range of 21 to 27 months would be “fair and appropriate.”

In its memo to Judge Cote, of Federal District Court in Manhattan, the government also noted that Mr. Weiner, while in Congress in 2007, co-sponsored the “Keeping the Internet Devoid of Sexual Predators Act,” a bill to require sex offenders to register their email addresses and instant-messaging accounts. The prosecutors said Mr. Weiner had, in public remarks, said “the internet is the predator’s venue of choice today.”

“Notwithstanding that he obviously grasped the importance of protecting minors from predatory conduct on the internet,” the prosecutors wrote, Mr. Weiner “readily engaged in extensive, inappropriate communications” with the girl. Such conduct, the prosecutors said, “suggests a dangerous level of denial and lack of self-control,” warranting a prison sentence.

In May, when Mr. Weiner made a surprise court appearance and pleaded guilty, he admitted that he had engaged in “obscene communications” with the teenager, “including sharing explicit images and encouraging her to engage in sexually explicit conduct,” just as he said he had done with women.