The former New York State congressman Anthony Weiner appeared in court in New York City Friday and pleaded guilty to sexting with a 15-year-old girl.

Weiner, 51, shed tears in the federal court and apologized as he made his plea, according to TMZ.

Weiner was charged with "transferring obscene material to a minor." He accepted a plea deal following an FBI investigation. As a result, he will have to serve prison time—21 to 27 months—and register as a sex offender. He also had to surrender his iPhone and pay a fine that could be as much as $350,000.

The teen, who lives in North Carolina, did not want to press charges, as she said the texting relationship was consensual, but Weiner said he was "committed to making amends to all those I have harmed."

Weiner said his “destructive impulses” have ruined his life, and said he has hit “rock bottom.”

Weiner and his wife, top Hillary Clinton staffer Huma Abedin, separated in 2016. In a case of adding insult to injury, she filed for divorce on the same day as her husband's guilty plea. Weiner checked into rehab for sex addiction last year.

Weiner ran for mayor of New York City in 2005 and 2013. He was a member of the House of Representatives from 1999-2011.

Weiner’s exact sentence will be determined by a judge at a later date.