Johnny Depp announced last week that he would no longer appear in the “Fantastic Beasts” film franchise — news that arrived on the tail of his loss in a libel case against a British tabloid that called him a “wife beater,” and nearly two months after production began on a third installment in the Harry Potter spinoff series.

“I have been asked to resign by Warner Bros. from my role as Grindelwald in Fantastic Beasts and I have respected and agreed to that request,” Depp wrote in a letter uploaded to Instagram on Friday.

Depp’s exit came as a surprise to crew members, according to the Hollywood Reporter, which stated in a piece published Monday afternoon that his “pay-or-play” contract requires the studio to pay his eight-figure salary regardless of whether he appears in the film. The dismissal nonetheless marks a major career repercussion for an actor still embroiled in a $50 million defamation lawsuit against his ex-wife, actress Amber Heard, who wrote an op-ed for The Washington Post in 2018 including a thinly veiled reference to her domestic abuse allegations against him.

A Warner Bros. spokesperson on Tuesday declined The Post’s request for additional comment on Depp’s contract, referring back to a statement from Friday that confirmed his departure from the franchise and thanked him for his contributions.

Legal proceedings played out publicly after Heard filed for divorce from Depp in May 2016, with tabloids circulating photographs and videos detailing the allegations Depp has repeatedly denied. Their divorce was finalized that August. In April 2019, after Depp’s lawyers claimed the op-ed Heard wrote in the wake of the #MeToo movement was based on the “categorically false” premise that Depp had abused her, she described more than a dozen specific allegations ranging from 2012 to 2016 and recalled fearing for her life.

Andrew Nicol, the judge in the libel case against the publisher of British tabloid the Sun, wrote in his final judgment last week that he believed Heard “was the victim of sustained and multiple assaults,” adding that the incidents “must have been terrifying.”

The Hollywood Reporter said that Warner Bros. “wanted to allow due process to take its course before making a decision on the embattled star’s future in the franchise.” Gellert Grindelwald, the dark wizard Depp played in 2016’s initial “Fantastic Beasts” film and its 2018 sequel, will be recast for the remaining three installments.

Depp isn’t the only person involved in the “Fantastic Beasts” franchise whose behavior has been scrutinized. Creator J.K. Rowling garnered controversy back in June when she doubled down on transphobic beliefs first made public last year. “Harry Potter” actors Daniel Radcliffe and Emma Watson responded by publicly expressing support for the trans community, as did “Fantastic Beasts” star Eddie Redmayne (who later landed in hot water himself by defending Rowling against online “vitriol”). Warner Bros. put out a vague statement referring to its “responsibility to foster empathy and advocate understanding of all communities and all people, particularly those we work with and those we reach through our content.”

The studio and Rowling, who wrote both “Fantastic Beasts” screenplays, previously stood by their decision to cast Depp as Grindelwald. Rowling wrote on her website in December 2017 that “conscience isn’t governable by committee. Within the fictional world and outside it, we all have to do what we believe to be the right thing.” Warner Bros. stated that the proceedings between Depp and Heard had been “jointly addressed by both parties, in a statement in which they said ‘there was never any intent of physical or emotional harm.’ ”

“Based on the circumstances and the information available to us, we, along with the filmmakers, continue to support the decision to proceed with Johnny Depp in the role of Grindelwald in this and future films.”

In an article published Monday evening, Variety attributed the studio’s change of heart three years later to the merger between AT&T and Time Warner, the parent company of Warner Bros., which occurred after the second “Fantastic Beasts” film had already wrapped. Since then, there “has been an overall lack of tolerance for the kind of controversy that every major studio has had to weather at one time or another when courting mercurial — but historically popular — talent like Depp,” the trade magazine reported.

“Fantastic Beasts” was Depp’s second major franchise after the successful “Pirates of the Caribbean” films (the fifth of which he was filming in Australia when he sustained a hand injury that later figured into legal proceedings with Heard). Though Disney hasn’t taken a firm stance as to whether Depp will return as Captain Jack Sparrow, producer Jerry Bruckheimer seemed to cast doubt on the prospect in May.

Depp maintained his innocence in his Friday Instagram post.

“My resolve remains strong and I intend to prove that the allegations against me are false,” he wrote. “My life and career will not be defined by this moment in time.”