Mr. Netanyahu and Mr. Gantz both professed interest in joining forces in a unity government, which polls showed most Israelis wanted, but Mr. Gantz said he would refuse to serve in a government with a prime minister who is under indictment, and Mr. Netanyahu insisted that under any agreement to rotate the prime minister’s job, he must serve first.

Mr. Netanyahu had little incentive to yield on that demand. He remains prime minister until a new government is formed, and retaining the job leaves him in better position to fight his legal battle.

He could, for instance, try to negotiate a plea deal with law enforcement authorities in which the charges are dropped in return for his departure from public life. A sweeping victory in the next election could even get him enough support to grant him parliamentary immunity from prosecution.

Mr. Netanyahu is accused of trading official favors worth hundreds of millions of dollars to Israeli media moguls for lavish gifts and positive news coverage. He has denied any wrongdoing, casting himself as the victim of a witch hunt by a left-wing elite that he says dominates the news media and has pressured the law enforcement authorities to pursue criminal investigations against him.

Fighting for his political survival, Mr. Netanyahu left nothing to chance in the Likud primary contest. He attended campaign rallies in up to five different towns a night and appealed to voters in Facebook Live videos, re-establishing his popularity within the Likud and firing up the party’s rank and file ahead of the more fateful contest against Mr. Gantz.