Before the sentence was pronounced, Mr. Weiner did not so much ask for leniency as try to make a case that he had accepted full responsibility for his crime, and that he was a changed man.
âI acted not only unlawfully but immorally, and if I had done the right thing, I would not be standing before you today,â he said, crying as he addressed the judge.
âThe prosecutors are skeptical that I have truly changed and I donât blame them,â he said. âI repeatedly acted in an obviously destructive way when I was caught.â
It was during that investigation that the F.B.I. discovered on Mr. Weinerâs laptop a trove of emails belonging to his wife, Huma Abedin, a senior aide to Hillary Clinton. That led to an announcement in late October by James B. Comey, then the F.B.I. director, that the bureau had opened a new inquiry into Mrs. Clintonâs handling of official email. The inquiry ended two days before the election; Mrs. Clinton has blamed Mr. Comey in part for her defeat.
The judge, Denise L. Cote of Federal District Court in Manhattan, told Mr. Weiner that his offense was âa serious crime that deserves serious punishment.â
She said that there was a uniform opinion among those who had examined him that he had âa disease that involves sexual compulsivity; some call it a sex addiction.â
The judge said Mr. Weiner was finally receiving âeffective treatment for this disease,â including attending group therapy and Sex Addicts Anonymous. âI find he is making an enormous contribution to others who are suffering from that same disease,â she added.
âBut the difficulty here,â the judge said, âis that this is a very strong compulsion, so strong,â she continued, that âdespite two very public disclosures and the destruction of his career on two occasions, he continued with the activity.â
She cited Mr. Weinerâs illegal exchanges with the girl on Skype, Snapchat and a site called Confide in early 2016. Prosecutors had said in their sentencing memo that during some of these communications, Mr. Weiner âused graphic and obscene language to ask the minor victim to display her naked body and touch herself, which she did.â
âThe defendant knew this young woman was in high school and getting her learnerâs permit,â Judge Cote said.
After the judge left the bench, Mr. Weiner remained seated at the defense table between his lawyers, Arlo Devlin-Brown and Erin Monju. He was bent deeply forward in his chair, sobbing, his face in his hands.
The judge also fined Mr. Weiner, who must surrender by Nov. 6, $10,000. She said he would also have to register as a sex offender.
During the hearing, Mr. Weiner looked tense and serious, sometimes clenching his jaw. At times, he blinked rapidly, his lips pursed and his nostrils flared. He sipped from a water bottle on the table before him.
When Judge Cote asked if he wanted to speak, he rose and began reading from a statement he had carried with him. His first words were strong and clear; by his third sentence, however, his voice began to break, and he paused often to clear his throat.
âI was a very sick man for a very long time,â he said, his voice growing higher-pitched and weaker.
âI have a disease but I have no excuse,â he continued. âI accept complete and total responsibility for my crime. I was the adult.â
Later, when the judge announced the sentence, Mr. Weiner, who let out a small cry, immediately slumped forward, his hands braced on the table for support. He then lifted his left hand to his face, cradling it, his eyes fixed on the table.
In a letter to the judge, Mr. Weiner had said he felt âprofoundâ regret for his crime, adding that his âcontinued acting out over years crushed the aspirations of my wife and ruined our marriage.â
Ms. Abedin filed her own one-page letter to the judge, asking for leniency on behalf of their son. She did not attend the sentencing.
His lawyers had sought probation for their client, citing what they described as Mr. Weinerâs âremarkable progressâ over the past year. In court, Mr. Devlin-Brown asked the judge to hold out prison as a possibility if necessary, âbut not apply it now, and give an opportunity for something positive to emerge from the wreckage of all of this.â
The prosecutors, Amanda Kramer and Stephanie Lake, in their sentencing papers, had said probation was âsimply inadequate.â The government had recommended a sentence within the range of 21 to 27 months.
âThere is a history here that simply cannot be ignored,â Ms. Kramer said in court. âWhat is required here to stop the defendant from reoffending, to fully pierce his denial and end this tragic cycle is a meaningful term of imprisonment.â
The judge also addressed one issue that Mr. Weinerâs lawyers had raised in their papers: questions about the teenagerâs motives and credibility. They noted she had received $30,000 for the DailyMail.com story and was âshoppingâ a book proposal.
The judge said the girlâs motives and the fact she had initiated the contact with Mr. Weiner were irrelevant: âShe was a minor. She was a victim. She is entitled to the lawâs full protection.â
Judge Cote also said that because of Mr. Weinerâs notoriety, there was âintense interest in this prosecution, in his plea, and his sentence.â
âSo there is the opportunity to make a statement that could protect other minors,â she added.
Mr. Devlin-Brown, in a statement, cited the judgeâs comment. âWe certainly hope this public service message is received,â he said, âbut it has resulted in a punishment more severe than it had to be, given the unusual facts and circumstances of the case.â
Joon H. Kim, the acting United States attorney in Manhattan, said Mr. Weinerâs sentence was âjustâ and âappropriate.â
Mr. Weiner left the courtroom without comment, and outside the courthouse, cameras flashing in his face, he stepped into the back seat of a dark green Ford Escape and was driven away.