Television news producer Robert Joel Halderman admitted on Tuesday to trying to shake down David Letterman in a bizarre extortion plot in which the CBS late night host took to the airwaves to acknowledge that he had had affairs with staffers on the show.

Halderman’s plea agreement to a charge of attempted grand larceny spares Letterman the spectacle of a public trial and Halderman a lengthy prison term. He will instead get a six-month jail sentence concurrent with five years probation, as well as 1,000 hours of community service.

Before a Manhattan court, Halderman apologized to Letterman and his family, as well as to his own former girlfriend, Stephanie Birkitt, one of Letterman’s former assistants. It was during Halderman’s relationship with Birkitt that he got wind that she had had sexual relations with Letterman.

“I attempted to extort $2 million from David Letterman by threatening to disclose personal and private information about him, whether true or false,” he said.

“I feel great remorse for what I have done.”

Halderman said that he delivered the threat to Letterman’s driver in the form of a screenplay treatment, which Halderman acknowledged was “just a thinly veiled threat to ruin Mr. Letterman if he did not pay me a lot of money.”

Under advisement of his attorney, Letterman met with Halderman on multiple occasions, and he contacted the Manhattan District Attorney’s Special Prosecution Bureau. That led to a sting operation in which Halderman was given a fake $2 million check. Halderman had been a producer for “48 Hours Mystery” and was suspended from the show after his arrest.

Letterman then testified before a grand jury on Oct. 1, admitting that he engaged in sexual relationships with staff members. That evening, he revealed the events of the case in an extended statement on “Late Show with David Letterman,” calling the series of events a “very bizarre experience” and “creepy.”

The revelations engulfed the host in tabloid glare, but they didn’t sink his ratings, particularly as he faced an ultimately ill-fated competition from Conan O’Brien.

Halderman’s attorney, Gerald Shargel, told reporters that his client had been jealous and under financial pressures. While they had been preparing a defense, portraying Halderman’s actions as an attempted business deal, his client chose to put the case behind him, he said.

Letterman issued a statement in which he thanked Manhattan prosecutors and the NYPD. “I had complete faith that a just and appropriate result was inevitable,” he said. Later in the day, he also thanked them on “Late Show,” saying that the matter was “handled professionally, skillfully and appropriately.” “I’d never been involved in anything like this in my life, and I was concerned and full of anxiety and nervous and worried,” he said on the show.

Manhattan District Attorney Cyrus R. Vance Jr. also praised Letterman “for making the difficult but unquestionably right decision to report this crime to my Office” and said that the plea agreement “provides punishment for the defendant and a measure of privacy for the victim.”

The Associated Press contributed to this report.