Play video content Breaking News TMZ.com

Anthony Weiner shed tears in federal court as he entered a guilty plea for sexting a 15-year-old girl, and agreed to serve prison time, and will also have to register as a sex offender.

The oft-disgraced Congressman appeared before the judge Friday in NYC and was charged with transferring obscene material to a minor. Weiner, who cried and apologized in court, surrendered to the FBI following its investigation.

According to the terms of his plea deal ... Weiner is agreeing to serve 21 to 27 months in prison, surrender his iPhone and pay a fine of up to $350,000. A judge will determine at a later date exactly what his sentence will be.

In court, Weiner stood with his attorney Arlo Devlin-Brown, and admitted his "destructive impulses" had destroyed his life and career. He said he has a sickness "but I do not have an excuse" -- and acknowledged he'd hit "rock bottom." He added he's "committed to making amends to all those I have harmed."