CBS chief executive Les Moonves is exiting the company, effective immediately, amid a flurry of sexual misconduct allegations.

The announcement on Sunday evening ends his 20-year tenure atop one of the country's most important media empires.

It also concludes a months-long battle for control of CBS between Moonves and the company's controlling shareholder, Shari Redstone. The CBS board is being reshaped, with six new directors, and Redstone is repeating her vow to consider new bids from potential buyers.

The shakeup may position CBS for a sale. But the company is also facing some continued reputational risk. There is widespread scrutiny about the prospect of Moonves being paid tens of millions of dollars on his way out the door.

Moonves is one of the media world's highest paid CEOs, so his severance package would normally be generous, even gargantuan.

But a huge payout to Moonves could stir shareholder ire in light of the disturbing harassment and assault allegations that have piled up against him.

With those optics in mind, CBS said Sunday night that Moonves and CBS will donate $20 million to organizations that support the #MeToo movement and other groups fighting for workplace equity for women.

The donation, which will be made immediately, will come out of any severance that Moonves might eventually be given.

Earlier in the day, a source said that Moonves stands to earn upward of $100 million.

But Sunday evening's announcement specified that any severance "will depend upon the results" of the ongoing internal investigations into his behavior.

In other words, the details and dollar amounts may not be determined for weeks or months.

The advocacy group Times Up said in a statement on Sunday afternoon, "We will accept nothing less than full transparency of the investigation's findings, a commitment to real change across all levels of CBS management and no reward for Les Moonves."

Boardroom battle and huge financial stakes

Sunday's developments are an extraordinary confluence of events — a boardroom battle royale and a #MeToo case at the C-suite level.

Moonves' allies will surely cast his exit as a corporate coup — a successful effort by Redstone to gain a tighter grip on CBS.

Redstone's allies will point to her position as controlling shareholder; accuse Moonves of plotting a jailbreak attempt; and cite the misconduct allegations.

The jailbreak happened earlier this year when Moonves and most members of the CBS board took steps to dilute Redstone's control. A blizzard of lawsuits and counter-suits ensued. A trial was set to start in October.

Through Sunday evening's settlement, all of those suits will be dismissed and CBS will return to some sense of normal corporate order.

Joseph Ianniello, who has been the CBS chief operating officer since 2013, will serve as president and acting CEO while the board looks for a new CEO.

On one level, this is a clear victory for Redstone, whose father Sumner Redstone bought CBS almost twenty years ago.

Moonves and Redstone were locked in a tug of war even before July 27, when Ronan Farrow of The New Yorker first reported on alleged harassment by Moonves. The CBS board initially resisted calls for Moonves to be suspended or forced out.

But his continued leadership of CBS became "untenable," an executive told CNN.

Moonves kept a relatively low profile in August, but remained in charge of the broadcasting behemoth. It is unclear when he first knew that he had to go.

Some sources close to Moonves said in August that he had vowed to fight both the allegations of wrongdoing and the legal war against Redstone.

But another source said he knew his exit was inevitable several months ago, even before Farrow's first story came out.

With settlement talks already underway, Farrow published a followup story on Sunday. He wrote that "six additional women have accused the television executive of sexual misconduct, as the board of the CBS Corporation weighs the terms of his departure."

Farrow said some of the women spoke out because they felt CBS was failing to take appropriate action against Moonves.

The CBS board had already hired two law firms to do an investigation. Now the firms have even more to examine.

Moonves is the first CEO of a Fortune 500 company to leave his job amid harassment allegations in the year since two investigations of Harvey Weinstein (one of them by Farrow) jump-started the #MeToo Movement.

In Farrow's first story, six women, some of whom were named, alleged harassment and other misconduct by Moonves and connected it to deeper problems at the company.

Some of the claims dated back several decades. Moonves acknowledged making mistakes in his past but said he never abused his power.

The accusations in the second story are even more serious.

'Serious allegations,' denials and ongoing investigations

"These are more numerous claims, these are six women all of them on the record, also describing more serious allegations," Farrow said on CNN's "Reliable Sources" shortly after The New Yorker published the followup. "This includes multiple allegations of either physically forced or coerced oral sex. It includes a case that resulted in a criminal investigation."

Moonves told Farrow in a statement that the "appalling accusations in this article are untrue."

He said he had consensual relations with three of the women named by The New Yorker "some 25 years ago before I came to CBS." He reiterated that he never abused his power and said he can only surmise that the allegations "are surfacing now for the first time, decades later, as part of a concerted effort by others to destroy my name, my reputation and my career."

Farrow had a different explanation.

He said on CNN that "these women are coming out now" because "they have been extraordinarily frustrated by what they perceive to be inaction on the part of CBS and its board. And that really is integral to what prompted this followup story."

While the law firms have been investigating, Moonves has been "allowed to stay and continue to run the company," a different outcome than many other "Me Too" cases, Farrow noted.

Farrow indicated that CBS has been aware of the new allegations for at least several days. "In the last week, as we reached out to CBS for comment," stories emerged about exit talks, Farrow said.

The Los Angeles Times reported on Wednesday night that CBS board members were talking about Moonves' potential exit. Discussions had focused on the size of a severance package, and on whether Moonves would move to a producer role, the Times reported.

"As of a couple of days ago, they were still talking about potentially letting him leave with a very generous exit package, up to the neighborhood of $100 million," Farrow said on CNN. "Many of the women found that very, very frustrating. They felt this was a board that has let a powerful man who makes a lot of money for this company, in the words of one person, 'get away with it.'"