Former New York representative Anthony Weiner was sentenced Monday to 21 months in prison for sexting with a 15-year-old girl, in a case that rocked Hillary Clinton's campaign for the White House in the closing days of the race.

Weiner, 53, dropped his head into his hand and wept as the sentence was announced by Judge Denise Cote in New York City. He must surrender to prison officials by Nov. 6.

The sentencing in Federal Court in New York City completed the sordid downfall of the New York Democrat, whose penchant for exchanging lewd messages and photos with young women online destroyed his career in Congress in 2011, doomed his bid for mayor of New York in 2013, wrecked his marriage to Clinton's closest aide, Huma Abedin, and became entangled in the 2016 presidential campaign.

Admitting "I have a sickness, but I do not have an excuse," Weiner pleaded guilty in May to transferring obscene material to a minor, punishable by up to 10 years in prison, for illicit contact with a North Carolina teenager.

"I am profoundly sorry," he said, reading from a page in front of him. "The crime I committed was my rock bottom.... I live a different and better life today."

Prosecutors said he sent her porn and got her to take her clothes off and touch herself on Skype. Assistant U.S. Attorney Amanda Kramer on Monday urged Cote to give Weiner a significant prison sentence to end his "tragic cycle" of sexting.

Weiner, right, is shown on Sept. 13 in a court appearance with Huma Abedin, the longtime Hillary Clinton aide who has announced her separation from Weiner. (Jefferson Siegel/The Daily News via AP)

In imposing sentence, the judge cited a need in such a highly publicized case to "make a statement that can protect other minors."

Cote noted that Weiner repeatedly got caught sexting and said that while he has made "great strides" in treatment, "the difficulty here is that this is a very strong compulsion."

He was also fined $10,000. After his sentence is served, there will be three years of supervised release and internet monitoring. He must also enrol in a sex-offender treatment program.

The FBI was investigating Weiner's contact with the high school student when it came across emails on his laptop between Abedin and Clinton, prompting 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.

'Dangerous level of denial'

Two days before election day, the FBI announced there was nothing new in the emails. But Clinton has blamed Comey's handling of the episode more than any other factor for her loss to Donald Trump. In a recent NBC interview, she called the FBI director's intervention "the determining factor" in her defeat.

Weiner's lawyers had argued in court papers that he was undergoing treatment and was profoundly sorry for subjecting the girl to his "deep sickness."

They also portrayed her as an instigator, saying she wanted to generate material for a book and possibly influence the presidential election. She has sold her story to the Daily Mail and sat down for a television interview with Inside Edition.

Prosecutors responded by arguing the victim's motives were irrelevant to the punishment, and said Weiner's habit of getting caught sexting "suggests a dangerous level of denial and lack of self-control."

By the time of Comey's October surprise, Abedin had announced her intention to separate from Weiner, although in a letter to court this summer, she hoped for probation, citing the effects on the couple's young son.

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, wearing his wedding ring, seemed pensive just before Monday's hearing began. His parents were in the courtroom but his wife wasn't. He and Abedin are currently going through divorce proceedings.

In her new memoir, What Happened, Clinton revealed that Weiner's wife "looked stricken" and burst into tears upon learning her husband had triggered Comey's "October surprise."

"This man is going to be the death of me," Abedin was quoted as saying.

Clinton called Comey's public intervention late in the election "the determining factor" in her loss in a recent NBC interview promoting her new book.