NEW YORK -- Anthony Weiner's sexting compulsion cost him his seat in Congress, his shot at becoming New York mayor and his marriage, and may have even denied Hillary Clinton the presidency. On Monday, it cost him his freedom.

Weiner, 53, dropped his head into his hands and wept as a federal judge sentenced him to 21 months behind bars for illicit online contact with a 15-year-old girl, his tears flowing long after the gavel came down on a case he called his "rock bottom."

As his parents but not his wife looked on in the courtroom, the New York Democrat was given until Nov. 6 to report to prison for misconduct that included getting the North Carolina high school student to strip and touch herself on Skype and Snapchat.

In handing down the sentence, U.S. District Judge Denise Cote cited a need in such a highly publicized case to "make a statement that can protect other minors."

The judge said Weiner's habit of exchanging sexually explicit messages and pictures with young women shows a "very strong compulsion" -- so strong that "despite two very public disclosures and the destruction of his career on two occasions, he continued with the activity."

Calling himself "a very sick man for a very long time," Weiner tearfully apologized to the teen and sought to assure the judge he had finally learned his lesson. He has been undergoing therapy.

"I stand before you because I victimized a young person who deserved better," he said, adding, "Your Honor, I'm not asking that you trust that my recovery is real. I ask you for the opportunity to prove that it is real."

Wearing a wedding band, he also spoke of his devotion to the 5-year-old son he has with his wife, Huma Abedin, formerly Clinton's closest aide. The couple is going through a divorce.

But prosecutor Amanda Kramer urged the judge to give Weiner a significant prison sentence to end his "tragic cycle" of getting caught sexting.

Weiner's habit led him to resign his House seat in 2011, doomed his 2013 run for mayor, and rocked Clinton's 2016 presidential campaign during the closing days of the race, when FBI agents investigating his contact with the teen came across emails on his laptop between Abedin and Clinton.

That discovery prompted then-FBI Director James Comey to announce in late October 2016 that he was reopening the probe of Clinton's use of a private computer server.

Two days before Election Day, the FBI declared there was nothing new in the emails. But in a recent interview, Clinton called Comey's intervention "the determining factor" in her defeat.

Weiner, once he has completed his prison sentence, must undergo internet monitoring and enrol in a sex-offender treatment program. He also was fined $10,000.

After the sentencing was over, he sat crying for several minutes in the courtroom. He left the courthouse without speaking to reporters.

Weiner's behaviour in all its lurid detail -- including his online alias "Carlos Danger" and a selfie of his bulging underwear -- turned him and his last name into an irresistible punchline for late-night comics and mortified his wife again and again.

Weiner attorney Arlo Devlin-Brown said his client probably exchanged thousands of messages with hundreds of women over the years and was communicating with up to 19 women when he encountered the teenager.

He cited the nation's capacity to forgive, recalling that Weiner, even after resigning from Congress in disgrace, was leading the New York mayoral primary race when new sexting disclosures emerged.

"In America they say there are second acts, but there are no third acts," the attorney said, "and after that Anthony was finished."

------

Associated Press writer Colleen Long in New York contributed to this story.