NEW YORK — Anthony Weiner, a former Democratic congressman, pleaded guilty Friday in New York to charges of sending obscene material to a minor.


The charges arose from a months-long sexually charged flirtation Weiner carried out with a 15-year-old high school sophomore in North Carolina. But he might go down in history for the unwitting role he played in the 2016 presidential election.


It was in the course of the sexual misconduct investigation that the FBI stumbled on a trove of emails on his laptop from his estranged wife, Huma Abedin, an aide to Hillary Clinton. That discovery in turn led then-FBI Director James Comey to announce a few days before the election he was reopening a probe into Clinton’s private emails — a statement that Clinton blamed in part for her loss to Trump.


The 52-year-old ex-congressman was once a rising star on the New York political scene, but his career was destroyed by repeated, embarrassing disclosures of sexually explicit texting over social media.


“I am guilty, your honor,” Weiner said tearfully, struggling to read a prepared statement. “I knew this was as morally wrong as it was unlawful.”


In the deal struck with prosecutors, Weiner entered a plea in U.S. district court in Manhattan to one count of sending obscene material to a minor. Although the charge carries a sentence of up to 10 years in prison, under the deal, prosecutors will ask for 21 to 27 months. Weiner will also have to register as a sex offender.


As part of the deal, Weiner has to give up his iPhone.