FORMER US congressman Anthony Weiner has been given a 21-month jail sentence for sexting with a 15-year-old girl in a case that may have cost Hillary Clinton the presidency.

The former Democratic congressman from New York had faced up to 27 months in jail after his guilty plea to a charge of transferring obscene material to a minor.

Prosecutors said he broke the law by having illicit contact with a 15-year-old girl on Skype and Snapchat. Weiner’s sexting habit destroyed his career in congress, his campaign for mayor and his marriage to Huma Adedin, a former aide to Clinton.

The case also became an issue in the closing days of last year’s presidential election. Then-FBI director James Comey cited emails discovered on a laptop used by Weiner to justify reopening the probe into Clinton’s private computer server.

The FBI was investigating Weiner’s contact with the North Carolina high school student when it came across emails between Abedin and Clinton.

Two days before election day, the Bureau announced there was nothing new in them, 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 parents were in the courtroom, but not his wife. He and Abedin, who have a five-year-old child, are going through divorce proceedings.

Weiner, 53, was also fined $10,000 dollars (£7400). After his sentence is served, he must undergo internet monitoring and must have no contact with his victim. He must also enrol in a sex offender treatment programme.

In her new memoir, What Happened, Clinton revealed that Weiner’s wife “looked stricken” and burst into tears upon learning her husband had triggered what she termed Comey’s “October surprise”.

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

Weiner dropped his head into his hand and wept as the sentence was announced by Judge Denise Cote in a New York federal courtroom. He must surrender to prison officials by November 6.