JERUSALEM — Israel’s attorney general said Thursday that neither the criminal charges Prime Minister Benjamin Netanyahu is facing nor the unusual terms of the coalition deal he struck with a former rival should disqualify him from forming a new government.

The opinion by Attorney General Avichai Mandelblit, who oversaw the investigation of Mr. Netanyahu and personally issued the indictment against him, could wind up strengthening his defenses against removal. It comes as Israel’s Supreme Court is to hear legal challenges on Sunday to Mr. Netanyahu’s power-sharing agreement with Benny Gantz, who fought him to a draw in three elections before giving up and joining him.

Mr. Netanyahu, who is accused of trading lucrative favors for gifts and positive press coverage in dealings with Israeli media moguls, is set to stand trial beginning May 24 on charges of bribery, fraud and breach of trust.

Mr. Gantz, who campaigned on a vow to topple Mr. Netanyahu and insisted he would never serve under a premier facing criminal charges, reversed himself and agreed to an unusual arrangement in which Mr. Netanyahu would serve as prime minister for 18 months, with the two men required to agree on most major decisions. Mr. Gantz would then take over for another 18 months.