Anthony Weiner, the former congressman convicted of sexting with a 15-year-old girl, has been released from a federal prison in Massachusetts to a transitional facility in New York and must register as a sex offender.

Weiner, 54, pleaded guilty in May 2017 to transferring obscene material to a minor. Four months later, he was sentenced to 21 months in federal prison.

Weiner must register as a sex offender and spend three years of supervised release.

Prosecutors said the teen initiated the communications with Weiner via Twitter in January 2016. The girl acknowledged she was a minor, but the contacts continued over Snapchat and other social media outlets.

Weiner was elected to Congress from Brooklyn in 1998 and served 12 years in the heavily Democratic district. In 2010, his star rose after making a dramatic speech before Congress in which he blasted Republicans for voting against a federal aid bill for first responders to the 9/11 terror attacks.

Weiner married Huma Abedin, a longtime aide to Hillary Clinton, in 2010. The power couple had a son in 2011. But he resigned his seat that year after admitting he had been exchanging explicit messages and photos with a half-dozen women.

He attempted a comeback in 2013 via a mayoral campaign that collapsed when it emerged he was sending explicit photos to a 22-year-old woman under the pseudonym "Carlos Danger."

Abedin separated from Weiner in 2016 and filed for divorce after his guilty plea. The relationship became a crucial factor in the 2016 presidential campaign when then-FBI director James Comey reopened an investigation into Clinton emails less than two weeks before Election Day. The FBI cited a batch of emails discovered in the Weiner probe.

Days later, the FBI said nothing new or damaging against Clinton had been discovered.