Former U.S. Congressman Anthony Weiner on Friday pleaded guilty in federal court to one count of sending obscene messages to a minor, ending an investigation into a "sexting" scandal that played a role in last year's U.S. presidential election.

Appearing before U.S. District Judge Loretta Preska in New York, Weiner, 52, agreed not to appeal any prison sentence of 27 months or less as part of his plea deal with federal prosecutors.

RELATED: A look at Anthony Weiner's sexting scandal



15 PHOTOS Anthony Weiner sexting scandal See Gallery Anthony Weiner sexting scandal New York mayoral candidate Anthony Weiner attends a campaign event in the Rockaways section in the Queens borough of New York July 31, 2013. Weiner, 48, had surged into the lead in polls for the Democratic Party primary before revelations last week that he had sent more sexually explicit messages to at least one woman after he resigned and promised to change his behavior. REUTERS/Eric Thayer (UNITED STATES - Tags: POLITICS ELECTIONS) NEW YORK, NY - JUNE 16: U.S. Rep. Anthony Weiner (D-NY) announces his resignation June 16, 2011 in the Brooklyn borough of New York City. The resignation comes ten days after the congressman admitted to sending lewd photos of himself on Twitter to multiple women. (Photo by Mario Tama/Getty Images) NEW YORK - JUNE 12: A group of Congressman Anthony Weiner's constituents rally for his resignation outside his Kew Gardens office June 12, 2011 in the Queens borough of New York City. Weiner, who has refused to resign, requested a temporary leave of absence from the House of Representatives for professional treatment in the wake of his internet messaging scandal. (Photo by Michael Nagle/Getty Images) U.S. Representative Anthony Weiner (D-NY) announces that he will resign from the U.S. House of Representatives during a news conference in Brooklyn, New York, June 16, 2011. Weiner resigned on Thursday over a weeks-long Internet sex scandal, succumbing to bipartisan calls for him to step down. REUTERS/Mike Segar (UNITED STATES - Tags: POLITICS) WASHINGTON - MAY 31: U.S. Rep. Anthony Weiner (D-NY) speaks to the media regarding a lewd photo tweet May 31, 2011 on Capitol Hill in Washington, DC. A close-up photo of underwear of a man was tweeted from Weiner's Twitter account addressed to a college student in Seattle. The photo was deleted soon after and Weiner has claimed his account was hacked. (Photo by Alex Wong/Getty Images) WASHINGTON - MAY 31: U.S. Rep. Anthony Weiner (D-NY) leaves after he spoke to the media regarding a lewd photo tweet May 31, 2011 on Capitol Hill in Washington, DC. A close-up photo of underwear of a man was tweeted from Weiner's Twitter account addressed to a college student in Seattle. The photo was deleted soon after and Weiner has claimed his account was hacked. (Photo by Alex Wong/Getty Images) Former porn actress Ginger Lee (L) and her attorney Gloria Allred (R) depart a news conference in New York, June 15, 2011. Lee said on Wednesday she had an e-mail relationship with embattled Representative Anthony Weiner and that he urged her to lie about their exchanges in the hope that a scandal surrounding him would die down. REUTERS/Brendan McDermid (UNITED STATES - Tags: POLITICS CRIME LAW) Sydney Leathers, one of the women at the center of the scandal, spoke exclusively to Inside Edition about growing speculation that Donald Trump is planning to dredge up the sexting scandal all over again because Abedin is often regarded as Clinton's closest confidante. Huma Abedin, an aide to U.S. Secretary of State Hillary Clinton (C), is pictured during a House Appropriations Committee hearing on Capitol Hill in Washington, in this March 10, 2011 photograph. Abedin, the wife of U.S. Representative Anthony Weiner (D-NY), ensnared in a sex scandal for sending lewd pictures of himself over the Internet, is pregnant, the New York Times reported on June 8, 2011. REUTERS/Hyungwon Kang/Files (UNITED STATES - Tags: POLITICS) NEW YORK, NY - JULY 26: Anthony Weiner, a leading candidate for New York City mayor, pauses while speaking with reporters in Staten Island on a visit to homes damaged by Hurricane Sandy on July 26, 2013 in New York City. It was recently revealed that Weiner engaged in lewd online conversations with a woman after he resigned from Congress for similar previous incidents. (Photo by Spencer Platt/Getty Images) A Times Square newstand with local papers displaying headlines July 24, 2013 about the latest sexting scandal involving New York City mayoral candidate Anthony Weiner. Weiner on Tuesday admitted sending lewd texts and photographs under the moniker 'Carlos Danger' to a young woman after resigning from Congress over a similar scandal. According to news website 'The Dirty,' Weiner, 48, used the name to contact the woman on Facebook and establish an online relationship with her which involved the exchange of intimate photographs. In a statement from his campaign team, Weiner confirmed that the latest allegations were substantially true but tried to present them as having been covered by his previous confession. AFP PHOTO / TIMOTHY CLARY (Photo credit should read TIMOTHY CLARY/AFP/Getty Images) The ABC Good Morning America Times Square Ticker flashes news July 24, 2013 about the latest sexting scandal involving New York City mayoral candidate Anthony Weiner. Weiner on Tuesday admitted sending lewd texts and photographs under the moniker 'Carlos Danger' to a young woman after resigning from Congress over a similar scandal. According to news website 'The Dirty,' Weiner, 48, used the name to contact the woman on Facebook and establish an online relationship with her which involved the exchange of intimate photographs. In a statement from his campaign team, Weiner confirmed that the latest allegations were substantially true but tried to present them as having been covered by his previous confession. AFP PHOTO / TIMOTHY CLARY (Photo credit should read TIMOTHY CLARY/AFP/Getty Images) A Times Square newstand with local papers displaying headlines July 24, 2013 about the latest sexting scandal involving New York City mayoral candidate Anthony Weiner. Weiner on Tuesday admitted sending lewd texts and photographs under the moniker 'Carlos Danger' to a young woman after resigning from Congress over a similar scandal. According to news website 'The Dirty,' Weiner, 48, used the name to contact the woman on Facebook and establish an online relationship with her which involved the exchange of intimate photographs. In a statement from his campaign team, Weiner confirmed that the latest allegations were substantially true but tried to present them as having been covered by his previous confession. AFP PHOTO / TIMOTHY CLARY (Photo credit should read TIMOTHY CLARY/AFP/Getty Images) Disgraced former US congressman Anthony Weiner, running for mayor of New York, fields questions at an after-hours event in the Chelsea district of New York city on August 12, 2013, organized by the Buzzfeed.com website. Opinion polls show Weiner lagging in the race for City Hall after he acknowledged that he kept on sending explicit Internet messages to women even after he resigned from Congress in a sexting scandal. AFP PHOTO / Robert MacPherson (Photo credit should read Robert MacPherson/AFP/Getty Images) FILE PHOTO -- New York mayoral candidate Anthony Weiner and his wife Huma Abedin attend a news conference in New York, July 23, 2013. REUTERS/Eric Thayer/File Photo Up Next See Gallery Discover More Like This HIDE CAPTION SHOW CAPTION of SEE ALL BACK TO SLIDE

The former Democratic congressman saw his political career implode after a series of scandals involving his inappropriate sexual exchanges with women online. U.S. authorities have been investigating reports that Weiner, 52, sent explicit messages last year to a teenage girl in North Carolina.

Federal agents seized Weiner's laptop during the probe and discovered a batch of emails from his wife, Huma Abedin, a senior aide to Hillary Clinton, the Democratic nominee for president in 2016.

As a result, James Comey, then the 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 has blamed her loss to Republican Donald Trump in part on Comey's announcement, even though Comey said two days before the election in November that the review had uncovered no new evidence.

More from :

Former U.S. Representative Brown of Florida found guilty of fraud

Town orders Native American tribe to take down teepees

Mystery surrounds Hart Island, NYC's mass grave site