Ex-US Rep. Anthony Weiner pleads guilty in sexting case

FILE - In this July 24, 2013 file photo, New York City mayoral candidate Anthony Weiner leaves his apartment building in New York. (AP Photo/Richard Drew, File)

NEW YORK (AP) — Former U.S. Rep. Anthony Weiner, whose penchant for sexting strangers online ended his political career and led to an investigation that upended the presidential race, pleaded guilty Friday to criminal charges in connection with his online communications with a 15-year-old girl.

Weiner pleaded guilty to a charge of transmitting sexual material to a minor and could get years in prison. He agreed not to appeal any sentence between 21 and 27 months in prison. He was already in federal custody ahead of the court hearing.

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 North Carolina girl

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

The investigation led 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, just days before the election, FBI Director James Comey stunned the country by announcing that his agency was reopening its closed investigation into Clinton's handling of State Department business on a private email server so it could analyze the newly discovered correspondence.

That inquiry was brief. 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 loss to Republican Donald Trump on 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 behavior.

His failed mayoral bid was the subject of the documentary "Weiner."

The investigation ultimately led to then-FBI Director James Comey's letter to Congress informing them that the probe of Clinton's email practices as secretary of state had been reopened. Clinton and others have suggested that letter cost her the election.

The charge Weiner is expected to plead guilty to could carry a sentence of up to ten years in prison.