Late Sunday, CBS announced that its chairman and chief executive, Leslie Moonves, will resign. That was the culmination of an explosive six weeks for the longtime executive, who has been publicly accused of sexual harassment and assault by 12 women.

Moonves was widely regarded as one of the most powerful men in media until July, when the New Yorker published the accounts of six women who alleged assault or harassment in an article by Ronan Farrow. On Sunday, the New Yorker published six more allegations, which included forced oral sex, Moonves exposing himself without consent and the use of physical violence and intimidation to silence the women. They also described a culture of downplaying accusations and promoting men even after the company settled allegations against them.

The company said that CBS chief operating officer Joseph Ianniello will take over as interim CEO and president — both Moonves’ titles — as the company looks for a permanent replacement for its longtime chief.

“For the past 24 years it has been an incredible privilege to lead CBS’s renaissance and transformation into a leading global media company,” Moonves said in a statement late Sunday. “Untrue allegations from decades ago are now being made against me that are not consistent with who I am. ... I am deeply saddened to be leaving the company.”

After the first New Yorker article came out in July, the board hired outside lawyers to conduct an investigation into Moonves and activists called for his removal.

Moonves is still expected to collect millions as part of a settlement with the board, though the company said it will withhold any decision on payment until after the investigation is complete. The executive is one of the best-compensated in media, making $69 million last year, according to regulatory filings.

According to a statement from the company, Moonves and CBS will also “donate $20 million to one or more organizations that support the #MeToo movement and equality for women in the workplace. The donation, which will be made immediately, has been deducted from any severance benefits that may be due Moonves following the Board’s ongoing independent investigation.”

A CBS spokesman on Sunday sent The Post a statement in response to the New Yorker story. “CBS takes these allegations very seriously. Our Board of Directors is conducting a thorough investigation of these matters, which is ongoing.”

‘This was one of the most sexist places I’ve ever worked’

A settlement does avoid a further public-relations nightmare for CBS as outside lawyers investigate Moonves, eliminating the possibility he is serving as CEO when findings are returned.

But the prospect that Moonves’s exit package would be dependent on the investigation has led to fears among some CBS employees that the inquiry will not be rigorous.

A message to CBS employees in August signed by the lead investigators, Nancy Kestenbaum and Mary Jo White, offered what a former CBS staffer said seemed like a halfhearted attempt at gathering information.

“We welcome speaking to anyone who has any information, including documents, to share about their experience working at CBS,” the message, which the Post obtained. The statement also said “We will also take steps to protect your identity to the full extent provided by law, if you ask that we do so.”

Rachel Bloom, the star of “Crazy Ex-Girlfriend” on the CBS co-owned CW, on Sunday tweeted strong words about a potential settlement.

“As an employee of CBS, I would just like to say that Les Moonves should be fired without getting a …. dollar.”

“The actions described in this article are those of sexual assault and shame on anyone else in the corporation who knew about his crimes,” Bloom added.

Activists, too, have pushed back against the way in which CBS has handled the events. Shaunna Thomas, co-founder of the women’s rights group Ultraviolet, decried any possible payment.

“CBS’ decision to fire Moonves for cause is clearly the right decision. If they reward Moonves’ decades of sexual harassment with a massive golden parachute, it will be shameful and compounds the damage of his decades of unchecked abuse,” she wrote in a message to The Post. “As the first Fortune 500 company executive to be held accountable, CBS is setting the new standard that should become the norm across corporate America: ‘if you abuse women, you lose your job and your golden parachute.’”

Entertainment president Kelly Kahl told reporters last month that the environment was a safe one for women. “We’re not saying we’re perfect. No large company is,” he said. “But I’m confident the culture of the entertainment division is very safe, very collaborative and very welcoming.”

Alleged victims were outspoken in delineating the accusations against Moonves. One of the women who spoke to Farrow in his Sunday report, longtime television executive Phyllis Golden-Gottlieb, said she filed a criminal complaint with police to report incidents that occurred as early as 1986, but the statute of limitations had expired. She and Moonves worked together at Lorimar-Telepictures.

Farrow reported that tension has permeated the company, with law firm investigators seeking interviews with staffers as other men in senior positions are accused of similar assaults. Jeff Fager, executive producer of “60 Minutes,” has been accused by several women who said he inappropriately touched them.

“I really felt like this was one of the most sexist places I’ve ever worked,” Sarah Johansen, who previously worked as an intern at CBS for Fager, told Farrow.

What’s next for CBS?

As part of the agreement, CBS and Shari Redstone’s controlling shareholder National Amusements will end their lawsuit as Redstone agrees not to merge the broadcaster with Viacom for at least two years. That move gives Moonves a victory in that arena; he sought to keep CBS operating as a separate concern.

“CBS is an organization of talented and dedicated people who have created one of the most successful media companies in the world,” Redstone said. “Today’s resolution will benefit all shareholders, allowing us to focus on the business of running CBS — and transforming it for the future.” Moonves did not comment in the statement.

The company also will replace about half the board, naming three women Candace Beinecke, Barbara Byrne and Susan Schuman in addition to well-known media figures such as Richard Parsons and Strauss Zelnick to director positions.

In recent years, Moonves has made a push for digital, particularly via All-Access, the network’s streaming service that with shows like “The Twilight Zone” and “Star Trek” has been one of broadcast television’s most ambitious.

Some Wall Street insiders were skeptical CBS would be able to continue as an independent company even with the two-year promise.

“CBS’s days as an independent public company are numbered,” said Lloyd Greif, a Los Angeles-based investment banker who closely follows the company.

“Without its long-standing leader, CBS is doomed,” he said, noting that “Who else is strong enough, either in management or on the board, or has sufficient institutional backing to stand up to Shari? It is only a matter of time before CBS is reunited with Viacom, particularly since National Amusements is in a position to block any other acquirer.”

An unintended consequence of #MeToo: More male managers avoid mentoring women or meeting alone with them

When men back away from these relationships, it can make it harder for women to get promoted

‘Working Woman’ highlights the insidiousness of workplace abuse

The Israeli film shows how simultaneously subtle and coercive sexual harassment can be

How Alyssa Milano became an A-list activist of the Me Too era

The star of ‘Who’s the Boss?’ and ‘Charmed’ says her acting funds her activism