NEW YORK (Reuters) - Former U.S. Representative Anthony Weiner was sentenced to 21 months in prison on Monday for sending sexually explicit messages to a 15-year-old girl, setting off a scandal that played a role in the 2016 U.S. presidential election.

Weiner, 53, started to cry as soon as the sentence was announced by U.S. District Judge Denise Cote in Manhattan. His wife Huma Abedin, an aide to Democratic presidential candidate Hillary Clinton, was not in the courtroom and has filed for divorce.

He pleaded guilty in May to transferring obscene material to a minor, and agreed he would not appeal any sentence of 27 months or less.

“I was a very sick man for a very long time, but I’m also responsible for the damage I have done,” Weiner read from a statement in court before he was sentenced. He said he was being treated, and asked Cote to spare him prison and sentence him to probation so he could continue treatment.

Weiner’s lawyer, Arlo Devlin-Brown, said that while Weiner exchanged sexually explicit messages with many women, all of the others were adults.

Cote said she believed Weiner was suffering from an addiction, and was serious about being treated. However, she said it was important to deter others from committing similar crimes.

“There is the opportunity to make a statement that could protect other minors,” she said.

Slideshow ( 8 images )

“We are of course disappointed that Anthony was sentenced to prison, particularly so given that Judge Cote found that the treatment program Anthony had engaged in for the past year was showing great promise and should be continued,” Weiner’s lawyer, Devlin-Brown, said in a statement Monday afternoon.

Weiner declined to speak to reporters as he left the courtroom. He was ordered to surrender by Nov. 6.

The investigation into Weiner’s exchanges with a North Carolina high school student roiled the 2016 U.S. presidential campaign in its final days, when authorities found emails on Weiner’s laptop from his wife.

Weiner, who wore his wedding band at the sentencing, and Abedin have a son, Jordan, who is 5 years old.

The discovery of the emails prompted James Comey, then director of the Federal Bureau of Investigation, to announce in late October that the agency was reopening its investigation into Clinton’s use of a private email server while she was U.S. secretary of state.

Clinton has said the announcement contributed to her upset loss to Republican Donald Trump, who had accused her of endangering national security by using the private server.

Slideshow ( 8 images )

President Trump fired Comey in May amid the FBI’s probe into whether his campaign colluded with Russia to defeat Clinton, a claim the president has denied.

Weiner represented parts of New York City in the U.S. House of Representatives for 12 years before resigning in 2011, after it emerged that he had exchanged sexually explicit messages with adult women.

In 2013, Weiner ran for New York City mayor, but was defeated in the Democratic primary after more lewd messages became public.

(This version of the story corrects paragraph 16 to say that Weiner did not drop out of the 2013 mayoral election, but instead was defeated).