Former congressman Anthony Weiner has wept in court as he apologised to a 15-year-old girl with whom he exchanged sexually explicit texts.
The judge accepted Weiner's guilty plea to a charge of transmitting sexual material to a minor, and he agreed to not appeal against any sentence between 21 and 27 months in prison.
The Democratic former US Representative apologised to the teenager, saying: "I have a sickness, but I do not have an excuse."
The judge told him he would have to register as a sex offender.
The FBI began investigating Weiner in September after the 15-year-old from North Carolina told the Daily Mail she and Weiner had exchanged lewd messages for several months.
She also accused him of asking her to undress on camera.
Weiner's penchant for sexting strangers online ended his political career and led to an investigation that upended the presidential race.
The investigation prompted FBI agents to seize his laptop computer, which led to the discovery of a new cache of emails that Democratic presidential candidate Hillary Clinton had sent to Huma Abedin, Weiner's wife.
In late October, days before the election, then FBI director James Comey stunned the country by announcing that his agency was reopening its closed investigation into Mrs Clinton's handling of State Department business on a private email server so it could analyse the newly discovered correspondence.
The inquiry was brief and Mr Comey announced shortly before the election that the new emails contained nothing to change his view that Mrs Clinton could not be charged with a crime, but she partly blamed her loss to Republican Donald Trump on Mr Comey's announcement.
Weiner, who represented New York in Congress from 1999 to 2011, resigned after revelations that he was sending sexually explicit messages to multiple women.
He ran for New York City mayor in 2013 and was leading several polls until it was revealed he had continued his questionable behaviour.
His failed mayoral bid was the subject of a documentary called Weiner.