NEW YORK (Reuters) - Former U.S. Congressman Anthony Weiner wept on Friday as he pleaded guilty to sending sexually explicit messages to a teenage girl, capping a “sexting” scandal that played a role in last year’s U.S. presidential election during its waning days.

Wearing a navy suit, maroon tie and his wedding band, a tearful Weiner, 52, described his conduct before U.S. District Judge Loretta Preska in New York City.

“I have a sickness, but I do not have an excuse,” Weiner said, apologizing to the 15-year-old girl to whom he sent inappropriate images and messages last year.

Hours after the court hearing, his wife Huma Abedin, a senior aide to 2016 Democratic presidential nominee Hillary Clinton, filed for divorce in a Manhattan court, according to the New York Post.

A lawyer for Abedin did not immediately respond to a request for comment.

The charge of transferring obscene material to a minor carries a maximum sentence of 10 years in prison, but Weiner is likely to get less when sentenced on Sept. 8. As part of his plea agreement, federal prosecutors said they would consider a term between 21 months and 27 months “fair and appropriate.”

The plea deal appeared to seal the demise of a once-promising political career derailed by a series of scandals, stemming from what Weiner described in court as a compulsive need to seek sexual attention from women on social media.

Slideshow ( 7 images )

The investigation into his exchanges with the teenage girl also roiled the 2016 U.S. presidential campaign days before Election Day.

While searching Weiner’s laptop, federal agents found a batch of emails from his wife. As a result, James Comey, then director of the Federal Bureau of Investigation, announced in late October that the agency was reviewing the messages to determine whether to reopen its investigation into Clinton’s handling of official correspondence.

Clinton, who was leading in national polls at the time, has blamed her loss to Republican Donald Trump in part on Comey’s announcement, even though the director said two days before the election in November that the review had uncovered no new evidence.

Abedin had announced her separation from Weiner last summer after the latest round of explicit messages emerged, including an image of Weiner’s crotch as he lay in bed with their young son.

‘DESTRUCTIVE IMPULSES’

The controversy over Clinton’s use of a private email server while she was U.S. secretary of state dogged her throughout the campaign. Trump accused Clinton of endangering national security by exposing classified information to potential hacking.

Slideshow ( 7 images )

In testimony to Congress two weeks ago, Comey said he felt “mildly nauseous” at the suggestion his actions may have swayed the election, but added that he had no regrets.

Trump fired Comey days later amid the FBI’s probe into whether Trump’s campaign colluded with Russia to defeat Clinton, an allegation the president has denied.

Weiner, who served parts of New York City for 12 years in the U.S. House of Representatives, resigned in 2011 after an explicit photograph was posted on his Twitter account. He initially claimed his account had been hacked but eventually acknowledged he had sent the image as well as inappropriate messages to several women.

Two years later, he announced a run for New York City mayor but dropped out of the race when more explicit messages became public.

The federal investigation into Weiner came to light last year after the Daily Mail, a British newspaper, published an interview with the North Carolina teen.

On Friday, Weiner said he has been receiving “intensive” mental health treatment since then.

“These destructive impulses brought great devastation to family and friends, and destroyed my life’s dream of public service,” Weiner said.

In a statement, acting U.S. Attorney in Manhattan Joon Kim said, “Weiner’s conduct was not only reprehensible, but a federal crime, one for which he is now convicted and will be sentenced.”