Anthony D. Weiner, the former Democratic congressman whose sexting scandals ended his political career and embroiled him in a tumultuous F.B.I. investigation of Hillary Clinton before the election, pleaded guilty to a felony on Friday, crying openly as he admitted to conduct that he knew was “as morally wrong as it was unlawful.”

The plea agreement ended a federal investigation into a series of sexually explicit pictures and messages that Mr. Weiner sent last year to a 15-year-old girl in North Carolina.

It capped the long, tortured downfall of Mr. Weiner, who ruined a once-promising career in Congress and then spoiled various attempts at resurrecting his reputation, all through his uncontrolled habit of using social media and texts to send explicit images to women.

It also cost him his marriage: His estranged wife, Huma Abedin, a top aide to Mrs. Clinton, filed for divorce from Mr. Weiner on Friday in New York, according to two people with knowledge of the action.