Former U.S. representative Anthony Weiner, whose penchant for sexting strangers ended his political career and led to an investigation that upended the presidential race, pleaded guilty Friday to criminal charges over his online communications with a 15-year-old girl.

In a Manhattan court, Weiner cried as he apologized to the teenager with whom he exchanged sexually explicit texts. He said he knew the texting was "as morally wrong as it was unlawful."

"I have a sickness, but I do not have an excuse," the former Democratic congressman from New York said.

In the statement admitting to correspondence with the girl from January to March 2016, whom he knew to be underaged, Weiner said he had "entered intensive treatment" that he is still undergoing, and taken "a moral inventory of my defects."

The FBI began investigating the Democrat in September of last year after a 15-year-old North Carolina girl told a tabloid news site that she and the disgraced former politician had exchanged lewd messages for several months.

She also accused him of asking her to undress on camera.

Pleading to the charge, which requires him to register as a sex offender, could bring a sentence of up to 10 years. But Weiner is likely to serve a much shorter term. He signed a plea agreement with prosecutors in which he agreed not to appeal any sentence between 21 and 27 months in prison. His lawyer can request leniency at a sentencing scheduled for Sept. 8.

Weiner had previously been caught sexting, paving the way to his resignation as a congressman in 2011. Two years later, another incident permanently damaged his bid for New York City mayor, a period captured in the documentary Weiner.

Laptop became part of Clinton probe

The investigation of Weiner's laptop in 2016 led to the discovery of a cache of emails from Democratic presidential nominee Hillary Clinton to her aide, Huma Abedin, Weiner's wife. It renewed a probe just two weeks before the election into Clinton's use of a private email server while she previously served as secretary of state.

Clinton Emails

Huma Abedin, Weiner's wife, is seen with her former boss Hillary Clinton on June 10, 2016. The use of Weiner's laptop became part of the investigation into Clinton's handling of classified material, a probe overseen by recently fired FBI director James Comey. (J. Scott Applewhite/The Associated PRess)

That inquiry was brief.

Then FBI Director James Comey announced shortly before the election that the new emails contained nothing to change his view that Clinton could not be charged with a crime. But Clinton partly blamed her election loss to Republican Donald Trump on Comey's decision to go public with the information.

More recently, Comey sent Congress a letter correcting prior sworn testimony that Abedin had sent "hundreds and thousands" of emails, including some with classified information, to the laptop primarily used by Weiner. Comey, in his final hours on the job before being fired, said in his letter it was in fact only "a small number" of emails.

By the time of Comey's October surprise, Abedin had announced her intention to separate from Weiner.

In court on Friday, Weiner wore his wedding ring and a dark blue suit with a maroon tie.

CBC's The Passionate Eye will re-air the documentary Weiner on June 17 at 10 p.m. ET on CBC News Network.

With files from CBC News