Anthony D. Weiner’s improbable campaign for mayor was engulfed on Tuesday by a new scandal involving explicit online messages, imperiling his political resurrection two years after he resigned from Congress over similar behavior.

Mr. Weiner, appearing solemn and a bit worn as he faced more than 100 journalists at a hastily arranged news conference, acknowledged that his habit of sending sexual images and text messages to female fans had continued for more than a year after he left Congress vowing to seek treatment and change his behavior.

“It’s in our rearview mirror, but it’s not far,” he said.

The revelation collides with the narrative Mr. Weiner has offered throughout the campaign, in which he has repeatedly suggested that he has spent his time since leaving Congress rehabilitating himself and repairing his family relationships. After a late entry into the Democratic primary, he had rapidly risen in the polls, and performed strongly in fund-raising, as his relentless focus on ideas and his omnipresence helped ease the concerns of many voters.

On Tuesday, seeming to recognize the fragility of his public standing, he pleaded with New Yorkers to trust his assertions that he is now a changed man, despite the news that his online adventures — some conducted under the pseudonym of Carlos Danger — had persisted through last summer, after the birth of his child.