He lost his seat in Congress, his bid to become mayor of New York City, and his marriage. He quite possibly destroyed Hillary Clinton’s shot at the presidency.
On Monday, Anthony D. Weiner, sobbing as the judge spoke, learned the final, personal cost of his seemingly uncontrollable habit of exchanging lewd texts and pictures with women: 21 months in prison.
Until now, Mr. Weiner, 53, had been the beneficiary of multiple second chances, resurrecting his political savvy and promise amid earnest vows that he had learned his lesson.
But this time, there would be no second chance for Mr. Weiner, who pleaded guilty in May to one count of transferring obscene material to a minor, and had faced up to 10 years in prison.
His texting habit fueled his long and tortuous downfall. But it was his most recent exchanges with a 15-year-old girl that were the most personally ruinous: his wife filed for divorce, he pleaded guilty and now faces imprisonment.
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 Escapade and was driven away.