Media magnate Rupert Murdoch with sons Lachlan, left, and James, in 2016. (Leon Neal/AFP/Getty Images)

Earlier this year, when Rupert Murdoch and senior executives at Fox News’s parent company signed Bill O’Reilly to a new multiyear contract, they knew something the rest of the world didn’t: The star host had been accused of sexual and verbal harassment by women at Fox five times over the preceding 15 years.

They knew it because the company, 21st Century Fox, had paid money to settle two of the complaints. They also knew that the public was unlikely to find out because attorneys for O’Reilly and the company had signed his accusers to agreements binding them to confidentiality. In exchange for their silence and a promise not to sue, the women received payments totaling $3 million from 21st Century Fox.

Those settlements came on top of some $10 million that O’Reilly himself had paid earlier to three other women who had complained about his behavior while working at Fox. They also came after a bruising sexual harassment scandal involving Fox News co-founder and chairman Roger Ailes last summer, one in which 21st Century Fox paid some $35 million to settle a lawsuit by former Fox presenter Gretchen Carlson and allegations against Ailes by several unidentified women. This was in addition to $40 million paid to Ailes as severance.

In effect, Rupert Murdoch and his sons James and Lachlan, who run 21st Century Fox, took a calculated risk. They re-signed O’Reilly — Fox News’s most valuable asset — fully aware of his history but in the apparent hope that they could continue with business as usual, according to knowledgeable people at the company. Just to be safe, however, the company added an unusual feature to O’Reilly’s new contract: A clause permitting 21st Century Fox to terminate him, with up to a year’s salary as severance, if new allegations arose.

(Peter Stevenson/The Washington Post)

In the end, the Murdochs’ bet on their guaranteed moneymaker didn’t pay off.

A scathing investigation by the New York Times in early April about the allegations surrounding O’Reilly triggered an advertiser exodus from his top-rated program, “The O’Reilly Factor,” and brought out at least three more complaints against the opinionated host. It ultimately led the Murdoch family to invoke the termination clause on Wednesday, ending O’Reilly’s 21-year career at Fox. He has maintained that the complaints against him are unfounded, and plans to return to the air Monday with his “No Spin News” podcast.

The O’Reilly debacle raises questions about 21st Century Fox’s stated commitment to ensuring a hostility-free environment. In one of their few public statements about the problem in the scandal-scarred Fox News Channel workplace, James, 44, and Lachlan, 45, said after Ailes’s ouster last summer, “We continue our commitment to maintaining a work environment based on trust and ­respect.”

Yet after making that pledge, the company settled two more allegations against O’Reilly — one with former anchor Laurie Dhue, who left the network in 2008, and another with Juliet Huddy, a former network host.

According to the Times, the company also offered last year to settle, for $1 million, a lawsuit brought by Andrea Tantaros, who appeared regularly on Fox News. Tantaros’s suit is against the network and Ailes, but she also claimed in her complaint that O’Reilly made unwelcome advances. Fox has denied her claims; her suit is in “confidential arbitration,” according to Irena Briganti, Fox News’s spokeswoman.

A spokesman for 21st Century Fox declined to comment for this article.

Through all of this, 21st Century Fox has taken steps to keep the allegations and settlements as quiet as possible.

In addition to binding Dhue, Huddy and other women who have settled to silence through nondisclosure agreements, most full-time employees at Fox have arbitration agreements that “force them into secret corporate courts,” said Nancy Erika Smith, the attorney who represented Carlson. ­“Secrecy is what allows harassers to keep it up,” she said.

As a corporate matter, 21st Century Fox has made minimal public disclosures about the cost and extent of the problems. The company’s entire official accounting of the Ailes drama is contained in a half-sentence buried in two quarterly 10Q reports, a financial disclosure document required by federal ­securities law.

“For the three months ended September 30, 2016,” the disclosure reads, “the Company recorded . . . approximately $35 million of costs related to settlements of pending and potential litigations following the July 2016 resignation of the Chairman and CEO of Fox News Channel after a public complaint was filed containing allegations of sexual harassment.” (The complaint referred to is Carlson’s lawsuit.)

The company has meanwhile kept its internal investigation of the Ailes and O’Reilly matters ­under wraps.

After Carlson filed suit, lawyers for the law firm Paul, Weiss, Rifkind, Wharton & Garrison were hired to look into the complaint and Fox’s workplace practices. 21st Century Fox called on the same firm this month after Wendy Walsh, a former contributor to O’Reilly’s program, formally complained about O’Reilly on a company hotline.

According to people at 21st Century Fox, the law firm’s findings weren’t contained in a written report. Instead, the lawyers presented their conclusions to the Murdochs in oral briefings, a step that would minimize leaks or unauthorized dissemination of a document.

Lisa Bloom, an attorney for Walsh and two other women who have alleged harassment by O’Reilly, said 21st Century Fox’s attorneys typically insist on some of the strictest nondisclosure terms in the business.

“Their strategy has been to duck and cover every time a woman complains of harassment in their workplace, and then to drive her out, pay her off and silence her,” Bloom said.

Attorneys Smith and Bloom both note that almost none of the women publicly identified as accusers continue to be employed by Fox. They also note a seemingly opposite fact: Many of the senior executives who were employed at the time Ailes and O’Reilly were allegedly harassing women continue to run Fox.

Among them are Bill Shine and Jack Abernethy, who became co-presidents of Fox News after Ailes’s departure.

In her lawsuit, Tantaros said Shine warned her to drop her harassment complaints about Ailes or face a campaign of retaliation.

A Fox contributor, Julie Roginsky, alleged in a lawsuit this month that Ailes repeatedly sexually harassed her and sabotaged her TV career after she refused his advances. She also named Shine in her suit, claiming that he retaliated against her when she refused to “malign” Carlson and join “Team Roger” after Carlson sued Ailes last year.

Attorneys for Huddy, who settled her allegations, alleged in an intent-to-sue letter last year that Abernethy had harassed Huddy and harmed her TV career while he was the head of the Fox TV station group.

In a statement, Briganti said the letter “contains substantial falsehoods, which [Abernethy has] vehemently denied.” She added that Shine denied the allegations in the Tantaros and Roginsky lawsuits.

The pattern of allegations, settlements and secrecy at 21st Century Fox suggests a kind of “organizational deviance” in which multiple actors play a role, said Mark Feldstein, a University of Maryland journalism professor who is writing a book about media scandals, including the ones involving Ailes and O’Reilly.

“Essentially, the Murdochs made a business calculation as to how much and how long they could get away with all this before the price they had to pay was too great to bear,” he said. “It’s not how [the parent company of] a news organization to supposed to behave. It’s not how any company is supposed to act.”