JERUSALEM (AP) — Israel’s embattled prime minister, Benjamin Netanyahu, has notched two critical victories in this week’s power-sharing agreement with his chief rival: He can stay in office throughout his upcoming corruption trial, and he can press forward with a potentially explosive plan to annex large parts of the occupied West Bank.

Netanyahu and former military chief Benny Gantz, leader of the Blue and White Party, announced their “national emergency government” late Monday, ending 16 months of political paralysis and narrowly averting an unprecedented fourth national election in just over a year.

The emergency government’s stated mission is to steer the country through the coronavirus crisis, which has killed 180 Israelis and put a quarter of the country out of work. But after a bruising period of prolonged political stalemate, both men also appear to have been driven toward each other by their deepest survival instincts.

Netanyahu and Gantz agreed to rotate 18-month terms as prime minister, and they have evenly divided key government ministries and parliamentary committees. In effect, each side will be able to veto the other's actions.

Commentator Sima Kadmon said the coronavirus crisis served as the pretext for the unlikely alliance. "The real goal was Netanyahu’s effort to buy time,” she wrote in the Yediot Ahronot daily.

An early test for the alliance will be an issue close to Netanyahu's heart: the annexation of large parts of the West Bank. Such a move would destroy any lingering hopes of establishing an independent Palestinian state and draw widespread international condemnation.

Netanyahu and his pro-settler base see an opportunity under the friendly administration of President Donald Trump who seeks re-election in November. Although their government is to focus on coronavirus issues for its first six months, Netanyahu persuaded Gantz to allow him to raise annexation plans in the Cabinet from July 1.

Netanyahu could still face some obstacles. The deal says any move would require U.S. support and need to take into account the opinions of key allies. Gantz has given annexation only lukewarm support. But the vague language of their deal allows Netanyahu to present the proposal to parliament — where he appears to have majority support for the idea — even without Gantz's backing.

Palestinian official Saeb Erekat called the coalition agreement a threat to regional peace and security. “It is an international responsibility to hold the new Israeli government accountable,” he said.

The coalition deal has also come under heavy criticism in Israel.

Through three bitter election campaigns in the past year, Gantz portrayed himself as the antithesis to Netanyahu and repeatedly vowed never to sit in a government with a prime minister suspected of serious crimes. After the most recent election last month, Gantz even began pushing legislation in parliament to ban the indicted Netanyahu from remaining as prime minister.

Yet with the clock ticking, and his fragile alliance unraveling, Gantz accepted Netanyahu’s invitation last month to form a government together. The sudden announcement angered many of his supporters and broke up the Blue and White alliance, leaving him with only a shrunken version of the party. A fourth election would likely have sent Gantz into political irrelevance.

Speaking in parliament Tuesday, Gantz vowed to uphold the rule of law.

“I took upon myself the mission to safeguard the democracy because I believe it is the most significant source of strength as a society,” he said.

Netanyahu also defended the deal as best for the nation. Yet for all of his talk in recent weeks about the coronavirus and national unity, leaks from the coalition negotiations indicated he was also motivated by his own personal survival as he prepares to go on trial.

Netanyahu has been charged with fraud, breach of trust and accepting bribes in a series of scandals. He denies the charges and says he is the victim of a hostile media and aggressive prosecution.

While Israeli law requires public officials to resign if charged with a crime, that does not apply to sitting prime ministers.

Although Netanyahu is supposed to step aside next year under the deal, it creates a new position of “designated prime minister” that would permit him to remain in office while on trial.

Netanyahu has been desperate to stay as prime minister. As the case against him has gained steam, the office has provided him a high-profile stage to lash out against his opponents and rally his base. And last month, his hand-picked justice minister managed to delay Netanyahu’s trial until late May.

Although Netanyahu will not be able to prevent the trial, he nonetheless will be able to continue to use his office as a bully pulpit throughout the proceedings.

Several nonprofit advocacy groups filed challenges to the coalition deal, asking the Supreme Court to ban an indicted politician, such as Netanyahu, from being allowed to form a new government. If the court rules in favor of the challenge, the deal could unravel and the country could still be plunged into new elections.

Yohanan Plesner, a former lawmaker who is now president of the Israel Democracy Institute, said the coalition agreement ends a difficult stalemate but offers little hope.

He said the government would likely make progress on consensus issues, like rescuing the economy and passing a budget.

But in other areas, including annexation, “I very much expect it to be very difficult,” he said. “It will be mainly a government of mutual vetoes and paralysis.”