Ronen Zvulun/Reuters

JERUSALEM — Israeli opposition parties on Wednesday reached a coalition agreement to form a government and oust Benjamin Netanyahu, the longest-serving prime minister in Israeli history and a dominant figure who has pushed his nation’s politics to the right.

The announcement by the parties could lead to the easing of a political impasse that has produced four elections in two years and left Israel without a stable government or a state budget. If Parliament ratifies the fragile agreement in a confidence vote in the coming days, it will also bring down the curtain, if only for an intermission, on the premiership of a leader who has defined contemporary Israel more than any other.

The new coalition is an unusual and awkward alliance between eight political parties from a diverse array of ideologies, from the left to the far right. It includes the membership of a small Arab party called Raam, which would become the first Arab group to join a right-leaning coalition in Israeli history.

While some analysts have hailed the coalition as reflecting the breadth and complexity of contemporary society, others say its members are too incompatible for their compact to last, and consider it the embodiment of Israel’s political dysfunction.

The alliance would be led until 2023 by Naftali Bennett, a religiously observant former settler leader who opposes a Palestinian state and wants Israel to annex the majority of the occupied West Bank. He is a former ally of Mr. Netanyahu often described as more right-wing than the prime minister.

If the government lasts a whole term, it would then be led between 2023 and 2025 by Yair Lapid, a centrist former television host considered a standard-bearer for secular Israelis.

The son of American immigrants, Mr. Bennett, 49, is a former software entrepreneur, army commando, chief of staff to Mr. Netanyahu and defense minister. His home is in central Israel, but he was once chief executive of an umbrella group, the Yesha Council, that represents Jewish settlements in the occupied West Bank. Until the most recent election cycle, Mr. Bennett was part of a political alliance with Bezalel Smotrich, a far-right leader.

Though Mr. Bennett’s party, Yamina, won just seven of the 120 seats in Parliament, the anti-Netanyahu forces could not form a government without his support, allowing him to set the terms of his involvement in the coalition.

Mr. Lapid, 57, is a former news anchor and journalist who became a politician nine years ago and later served as finance minister in a Netanyahu-led coalition. His party placed second in the general election in March, winning 17 seats. But Mr. Lapid considered the ouster of Mr. Netanyahu more important than demanding to go first as prime minister.

Mansour Abbas, leader of the Arab party Raam, signing a coalition agreement with Yair Lapid, left, and Naftali Bennett.
United Arab List Raam, via Agence France-Presse — Getty Images

Yair Lapid, the leader of the Israeli opposition, had until midnight on Wednesday to cobble together an unlikely coalition to topple Benjamin Netanyahu. He needed almost every minute — leaving it until 11:22 p.m. to inform Reuven Rivlin, Israel’s largely ceremonial president, that he had assembled an eight-party alliance.

“The government will do everything it can to unite every part of Israeli society,” Mr. Lapid said in a statement released shortly after his call with Mr. Rivlin.

Mr. Lapid’s celebrations will be put on hold for several days, however. The speaker of the Israeli Parliament, Yariv Levin, is a member of Mr. Netanyahu’s party, Likud, and can use parliamentary procedure to delay the confidence vote until Monday, June 14, constitutional experts said.

In the meantime, Mr. Netanyahu’s party has promised to pile pressure on wavering members of Mr. Lapid’s fragile coalition, formed of hard-right parties, leftists, centrists and Arab Islamists, in a bid to persuade them to abandon the coalition. Many of them already feel uncomfortable about working with each other, and have made difficult compromises to join forces in order to push Mr. Netanyahu from office.

Mr. Lapid himself agreed to give Naftali Bennett, a hard-right former settler leader who opposes Palestinian statehood, the chance to lead the government until 2023, at which point Mr. Lapid will take over.

In a sign of the friction to come, Raam, the Arab Islamist party, announced that it had joined the coalition after receiving assurances about improvements to the Arab minority’s land and housing rights that many hard-right Israelis deem unacceptable, including the regularization of three illegally constructed Arab towns in the Negev desert.

An hour before the deal was announced, one hard-right lawmaker, Nir Orbach, whose party colleagues say he has been particularly unsure about joining the coalition, tweeted: “We are not abandoning the Negev. Period.”

The fact that these tensions were on full display even before the coalition was officially formed has left many Israelis wondering whether it will last more than a few months, let alone its full term.

Should the coalition collapse, analysts believe Mr. Lapid may emerge with more credit than Mr. Bennett. While Mr. Bennett gets first crack at the premiership, his decision to work with centrists and leftists has angered his already small following.

“Lapid has made a very strong set of decisions, conveyed an amazing level of maturity and really made a big statement about a different kind of leadership,” said Dahlia Scheindlin, an Israeli political analyst and pollster at the Century Foundation, a New York-based research group. “That will not be lost on the Israeli public.”

Gil Cohen-Magen/Agence France-Presse — Getty Images

Now that opposition parties have reached agreement on a coalition government, it has up to seven days to present the government to Parliament for a vote of confidence.

Some disagreements within the fractious coalition were still being ironed out until shortly before the deadline on Wednesday, at midnight in Israel.

And with the fate of the new coalition dependent on a narrow margin and hanging on every single vote, Prime Minister Benjamin Netanyahu and his allies were on the hunt for potential defectors leading up to the announcement, and signaled that they would continue until the vote of confidence.

The coalition, ranging from right to left, is united primarily by its opposition to Mr. Netanyahu, the prime minister since 2009.

Israel has held four parliamentary elections in two years, all of them inconclusive, leaving it without a stable government or state budget. If the opposition fails to form a government, it could lead to yet another election.

Sebastian Scheiner/Associated Press

Naftali Bennett, who is poised to become Israel’s next prime minister, is a former high-tech entrepreneur best known for insisting that there must never be a full-fledged Palestinian state and that Israel should annex much of the occupied West Bank.

The independently wealthy son of immigrants from the United States, Mr. Bennett, 49, first entered the Israeli Parliament eight years ago and is relatively unknown and inexperienced on the international stage. That has left much of the world — and many Israelis — wondering what kind of leader he might be.

A former chief of staff to Prime Minister Benjamin Netanyahu, Israel’s longest-serving prime minister, Mr. Bennett is often described as more right-wing than his old boss. Shifting between seemingly contradictory alliances, Mr. Bennett has been called an extremist and an opportunist. Allies say he is merely a pragmatist, less ideological than he appears, and lacking Mr. Netanyahu’s penchant for demonizing opponents.

In a measure of Mr. Bennett’s talents, he has now pulled off a feat that is extraordinary even by the perplexing standards of Israeli politics. He has all but maneuvered himself into the top office even though his party, Yamina, won just seven of the 120 seats in the Parliament.

Mr. Bennett leveraged his modest but pivotal electoral weight after the inconclusive March election, Israel’s fourth in two years. He entered coalition talks as a kingmaker, and appears ready to emerge as the one wearing the crown.

Mr. Bennett has long championed West Bank settlers and once led the council representing them, though he is not a settler, himself. He is religiously observant — he would be the first prime minister to wear a kipa — but he will head a governing coalition that is largely secular.

He would lead a precarious coalition that spans Israel’s fractious political spectrum from left to right, and includes a small Arab, Islamist party — much of which opposes his ideas on settlement and annexation. That coalition proposes to paper over its differences on Israeli-Palestinian relations by focusing on domestic matters.

Mr. Bennett has explained his motives for teaming up with such ideological opposites as an act of last resort to end the political impasse that has paralyzed Israel.

“The political crisis in Israel is unprecedented on a global level,” he said in a televised speech on Sunday. “We could end up with fifth, sixth, even 10th elections, dismantling the walls of the country, brick by brick, until our house falls in on us. Or we can stop the madness and take responsibility.”

Dan Balilty for The New York Times

One of the most unlikely kingmakers involved in the formation of a new government is Mansour Abbas, the leader of the small Arab party known by its Hebrew acronym, Raam, with four seats in the current Parliament.

Under an 11th-hour deal, Raam formally agreed to join a Lapid-Bennett coalition government, though it would not hold any Cabinet seats. That was something of a surprise, as the party was expected to remain outside the coalition, while supporting it in a confidence vote in the Parliament. Some Arab lawmakers played a similar role by supporting Yitzhak Rabin’s government from the outside in the 1990s.

For decades, Arab parties have not been directly involved in Israeli governments. They have been mostly shunned by other parties, and are leery of joining a government that oversees occupation of the Palestinian territories and Israel’s military actions.

But after decades of political marginalization, many Palestinian citizens, who make up a fifth of Israel’s population, have been seeking fuller integration.

Israel’s early, leftist governments included Arab parties that were closely affiliated with the mostly Jewish parties. Raam would be the first independent Arab party in government, and the first Arab party of any kind in a right-leaning government.

Raam has been willing to work with both the pro- and anti-Netanyahu camps since the March election and to use its leverage to wrest concessions for the Arab public. The party has refused to commit to a deal unless it gets assurances for greater resources and rights for Israel’s Arab minority, including reforms to housing legislation that potential hard-right coalition partners do not accept.

Corinna Kern/Reuters

Sitting in her office in Parliament on Wednesday afternoon, Idit Silman, a hard-right lawmaker, flicked through hundreds of recent text messages from unknown numbers.

Some were laced with abusive language. Some warned she was going to hell. All of them demanded that her party abandon coalition negotiations with an alliance of centrist, leftist and right-wing lawmakers seeking to replace Prime Minister Benjamin Netanyahu for the first time in 12 years.

“It’s very hard,” Ms. Silman said. “People would rather put pressure on Idit Silman than see Benjamin Netanyahu leave Balfour Street,” she added, in a reference to the location of the prime minister’s official residence.

As opposition negotiators race to meet a midnight deadline to agree on a new government, supporters of Mr. Netanyahu and his Likud party were working overtime to pressure Ms. Silman and other members of the right-wing Yamina party.

Many right-wing Israelis see Yamina’s turn against Mr. Netanyahu as a betrayal.

This onslaught gave Ms. Silman and her colleagues pause for thought — and an incentive to be seen as prolonging the negotiations for as long as possible. Though Yamina did finally join the coalition on Wednesday night, Mr. Netanyahu’s party, Likud, is likely to continue to play on these fears.

Parliament might not hold a vote of confidence in a new government for another 10 days, giving Mr. Netanyahu more time to persuade Yamina lawmakers to reverse course.

His party has already promised to keep goading Ms. Silman and her colleagues.

“Behind the scenes,” said a senior Likud official, speaking on the condition of anonymity, “the Likud party is ramping up the pressure, particularly on the weakest links.”

The pressure has been relentless for days, since the phone numbers of Ms. Silman and her colleagues, they say, were posted on several WhatsApp and Facebook groups. That has prompted a barrage of messages — and not just from Israelis. Evangelical pastors in the United States have weighed in, and so have Hasidic activists in Britain, among many others.

The Likud party denies accusations that it posted any numbers publicly.

When Ms. Silman turned up at her local synagogue last week, she found several slick posters outside, each with her portrait overlaid with the slogan: “Idit Silman stitched together a government with terror supporters.”

For days, protesters have picketed her home, shouted abuse at her children, and trailed her by car in a menacing fashion, she said.

Yamina’s leader, Naftali Bennett, decided to negotiate with the opposition on Sunday night, after months of wavering. His calculus was based on realism, analysts say: Mr. Netanyahu cannot form a coalition, even with Mr. Bennett’s support. So Mr. Bennett can either fall in with the opposition, who have offered him the chance to be prime minister — or force the country to a fifth election in little more than two years.

“We always ask ourselves this question,” Ms. Silman said on Wednesday afternoon. “Is it right? Can we do something else?”

Pool photo by Yonatan Sindel

Naftali Bennett, who leads a small right-wing party, and Yair Lapid, the centrist leader of the Israeli opposition, have joined forces to try to form a diverse coalition to unseat Benjamin Netanyahu, Israel’s longest-serving prime minister.

Spanning Israel’s fractious political spectrum from left to right, and relying on the support of a small Arab, Islamist party, the proposed coalition, dubbed the “change government” by supporters, could signal a profound shift for Israel. Its leaders have pledged to end the cycle of divisive politics and inconclusive elections.

The opposition parties announced a coalition agreement on Wednesday. But even if they survive a vote of confidence in the Parliament and form a government, toppling Mr. Netanyahu, how much change would their “change government” bring, when some of the parties agree on little else besides antipathy for Israel’s longest-serving leader?

Mr. Bennett, whose party won seven seats in Parliament, is often described as further to the right than Mr. Netanyahu. While Mr. Netanyahu eroded the idea of a two-state solution to the Israeli-Palestinian conflict, Mr. Bennett, a religiously observant champion of Jewish settlement in the occupied West Bank, openly rejects the concept of a sovereign Palestinian state and has advocated annexing West Bank territory.

Still, though the coalition will include several parties that disagree on both those issues, they have agreed to allow Mr. Bennett to become prime minister first.

If the coalition deal holds, Mr. Bennett would be replaced for the second part of the four-year term by Mr. Lapid, who advocates for secular, middle-class Israelis and whose party won 17 seats.

By conceding the first turn in the rotation, Mr. Lapid, who has been branded as a dangerous leftist by his opponents on the right, smoothed the way for other right-wing politicians to join the new anti-Netanyahu alliance.

In a measure of the plot twists and tumult behind this political turnaround, Mr. Bennett had pledged before the election not to enable a Lapid government of any kind or any government reliant on the Islamist party, called Raam.

The coalition would stand or fall on the cooperation between eight parties with disparate ideologies and, on many issues, clashing agendas.

In a televised address on Sunday night, Mr. Bennett said he was committed to fostering national unity.

“Two thousand years ago, there was a Jewish state which fell here because of internal quarrels,” he said. “This will not happen again. Not on my watch.”

Pool photo by Ronen Zvulun

Even as the country and its Parliament remained deeply divided over the formation of a new government, Israeli lawmakers came together on Wednesday to elect a new president, Isaac Herzog, a former leader of the Labor party and government minister.

Displaying a rare degree of consensus in a secret ballot, they voted overwhelmingly for Mr. Herzog, who currently serves as the chairman of the quasi-governmental Jewish Agency for Israel, which helps deal with immigration, interacts with the Jewish diaspora and runs social programs.

The president plays a mostly symbolic role as a national unifier in Israel’s fractious parliamentary democracy, where the prime minister wields the most power.

One of a president’s main responsibilities is to grant a candidate the task of forming a government after elections. In Israel’s current, fragmented politics, which have produced four inconclusive elections in two years, that involves more than the usual level of skill, legal interpretation and discretion.

The president can also play an important role in Israeli diplomacy and has the power to pardon convicted criminals and exercise clemency by reducing or commuting sentences.

Mr. Herzog, 60, the grandson of the first chief rabbi of Israel and the son of one of the country’s earlier presidents, Chaim Herzog, will take over from the current president, Reuven Rivlin, in July.

“Our challenges are many and should not be taken lightly,” Mr. Herzog said in his acceptance speech. “I intend to be the president of all Israelis, to lend an attentive ear to every position and respect every person.”

Mohammed Saber/EPA, via Shutterstock

Less than a month ago, an eruption of intense fighting between Israel and Hamas militants in the Gaza Strip plunged Israeli and Palestinian communities into chaos. As the civilian casualties grew, overwhelmingly on the Gaza side, the conflict polarized Israeli society, and the world, in ways seldom seen before.

At least 230 people were killed in Gaza during the war, including at least 65 children, while in Israel at least 12 were killed, including two children. Gaza’s infrastructure, already ailing, was gutted by Israeli airstrikes on the densely populated territory. And Israeli towns and cities within range of Hamas rockets went into repeated, frightening lockdowns in shelters.

The war also spurred unrest within Israel and the occupied territories that has been more explosive than any in years. It has inspired a new era of Palestinian activism, and has shifted the ground politically, coloring the drama that was playing out in Israel on Wednesday.

Here is what to know about the 11-day war, and its lasting effects.

JERUSALEM — For Israelis, the possible downfall of Prime Minister Benjamin Netanyahu, the country’s longest-serving leader, is an epochal moment. Israeli media have barraged their audiences with reports and commentary on the opposition attempts to form a government.

But for many Palestinians, the political drama has prompted little more than a shrug and a resurgence of bitter memories.

During Mr. Netanyahu’s current 12-year tenure, the Israeli-Palestinian peace process fizzled, as Israeli and Palestinian leaders accused each other of obstructing the process, and Mr. Netanyahu expressed increasing skepticism about the possibility of a sovereign Palestinian state.

But to many Palestinians, his likely replacement as prime minister, Naftali Bennett, would be no improvement. Mr. Bennett is Mr. Netanyahu’s former chief of staff, and a former settler leader who outright rejects Palestinian statehood.

Instead, many Palestinians are consumed by their own political moment, which some activists have framed as the most pivotal in decades.

The Palestinian polity has long been physically and politically fragmented between the American-backed Palestinian Authority in the occupied West Bank; its archrival, Hamas, the Islamic militant group that rules Gaza; a Palestinian minority inside Israel whose votes might make or break an Israeli government; and a sprawling diaspora.

But spurred by last month’s 11-day war between Israel and Hamas in Gaza, and the worst bout of intercommunal Arab-Jewish violence to have convulsed Israel in decades, these disparate parts suddenly came together in a seemingly leaderless eruption of shared identity and purpose.

In a rare display of unity, hundreds of thousands of Palestinians observed a general strike on May 12 across Gaza, the West Bank, the refugee camps of Lebanon and inside Israel itself.

“I don’t think whoever is in charge in Israel will make a great deal of difference to the Palestinians,” said Ahmad Aweidah, the former head of the Palestinian stock exchange. “There might be slight differences and nuances, but all mainstream Israeli parties, with slight exceptions on the extreme left, share pretty much the same ideology.”

The strike in mid-May, Mr. Aweidah said, “showed that we are united no matter what the Israelis have tried to do for 73 years: categorizing us into Israeli Arabs, West Bankers, Jerusalemites, Gazans, refugees and diaspora.”

“None of that has worked,” he said. “We are back to square one.”