NEW YORK ― Former Rep. Anthony Weiner (D-N.Y.) pleaded guilty on Friday to a federal obscenity charge after he sent explicit text messages to a minor.

Weiner turned himself over to the FBI on Friday morning, and by 11:30 a.m. he was a convicted sex offender. He stood in a suit in Manhattan federal court, sobbing as he described how he met a stranger online “whom I knew to be 15 years old.”

“I engaged in obscene communication with this teen, just as I had done and continued to do with adult women,” Weiner said in front of Judge Loretta Preska.

He read from a letter he prepared for his plea, often pausing as he tried to compose himself.

“I accept full responsibility for my conduct,” he said, crying. “I have a sickness but I do not have an excuse. ... I apologize to the teenage girl who I mistreated so badly.”

Full copy of Anthony Weiner's statement from court today pic.twitter.com/s74V9trD9S — Noah Remnick (@NoahRemnick) May 19, 2017

The plea, filed in the Southern District of New York, comes nearly six years after Weiner, once considered a rising star of the Democratic Party, resigned from Congress after tweeting lewd images. Later reports revealed he had sent sexually explicit messages to multiple women.

“Weiner’s conduct was not only reprehensible, but a federal crime, one for which he is now convicted and will be sentenced,” the Department of Justice said in a statement.

Weiner is set to be sentenced Sept. 8. As part of his plea deal, he faces between 21 months and 27 months in prison. If sentenced to fewer than 27 months, he won’t be allowed to appeal.

Weiner will have to register as a sex offender, and he agreed to forfeit his iPhone.

Huma Abedin, his estranged wife and a close aide to Hillary Clinton, filed for divorce Friday in Manhattan Supreme Court, according to the New York Post.

I engaged in obscene communication with this teen, just as I had done and continued to do with adult women. Former Rep. Anthony Weiner (D-N.Y.)

The Daily Mail reported in September that Weiner had exchanged pictures and sexual messages with a 15-year-old girl. Weiner’s lawyers tried to dissuade the U.S. Attorney’s office from bringing charges, according to sources that spoke to The Wall Street Journal.

Weiner’s lawyers negotiated with federal prosecutors to avoid child pornography charges, the New York Daily News said.

TIMOTHY A. CLARY via Getty Images Weiner leaves federal court in New York on Friday.

Officials began to investigate Weiner over the allegations last year, and the probe into Weiner even affected the 2016 presidential campaign. Federal agents seized Weiner’s laptop and other electronics, on which they found emails belonging to Abedin. Just days before the presidential election, then-FBI Director James Comey publicly informed Congress of the existence of the new emails pertaining to an investigation into Clinton. Clinton has said Comey’s decision is part of the reason she lost the election.

Weiner ran for mayor of New York City in 2013, but lost badly in the Democratic primary after it was revealed that he had exchanged explicit messages with more women after he resigned from Congress.

Abedin and Weiner announced they were separating in August.

Clarification: Language has been amended to describe more accurately the end of Weiner’s 2013 mayoral campaign.