Benjamin Netanyahu, Israel’s longest-serving leader, is on the verge of losing power as his opponents strike a deal that would replace him with an ultranationalist, Naftali Bennett.JERUSALEM — Israeli opposition parties announced on Wednesday that they had 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 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. While some analysts have hailed it as a reflection of 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 former settler leader and standard-bearer for religious nationalists, 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.It was Mr. Lapid who was picked by the president, Reuven Rivlin, four weeks ago to try to form a new government. And it was Mr. Lapid who called Mr. Rivlin at 11:22 p.m. on Wednesday night, with just 38 minutes left before his mandate expired, to inform him that he had assembled a fragile coalition.Mr. Lapid, the Yesh Atid Party leader, speaking to reporters in Tel Aviv, last month.Amir Levy/Getty Images“I commit to you, Mr. President, that this government will work to serve all the citizens of Israel, including those who aren’t members of it, will respect those who oppose it, and do everything in its power to unite all parts of Israeli society,” Mr. Lapid said, according to a readout provided by his office.Mr. Bennett, 49, is the son of American immigrants, and a former software entrepreneur, army commando and chief of staff to Mr. Netanyahu. 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, Mr. Netanyahu could not be ousted 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.To avoid exacerbating their differences, Mr. Lapid and Mr. Bennett have promised to focus on largely technocratic issues like the economy and infrastructure, and to stay away from more contentious topics such as trying to resolve the Israeli-Palestinian conflict.Mr. Bennett, left, speaking with Mr. Lapid during a special session of the Knesset.Pool photo by Ronen ZvulunBut some commentators say Mr. Bennett’s party will be under pressure to prove to their supporters that their right-wing instincts have not been dimmed by their coalition partners.In a harbinger of potential tensions to come, talks almost collapsed on Wednesday after a disagreement over whether a key lieutenant to Mr. Bennett, Ayelet Shaked, a proponent of major judicial reform, would be allowed to join a committee that appoints new judges.And some leftist and centrist ministers are expected to rile their right-wing partners by promoting police reform or advocating curbs on settlement expansion.The alliance will also include an Arab Islamist party, Raam, which would become the first independent Arab group to join a governing political alliance in Israeli history. The agreement “secures the position of the Arab parties as an influential and legitimate player in the political arena,” the party said in a statement.But its participation is also expected to become a point of friction. Mr. Bennett briefly pulled out of coalition talks during the recent war in Gaza, wary of participating in an alliance with a party run by Palestinian citizens of Israel.Mr. Bennett speaking with reporters on Sunday.Pool photo by Yonatan SindelRaam joined the coalition on the promise of greater rights and resources for Israel’s Arab minority — but some of its demands, including the repeal of a controversial housing law that disproportionately hinders the Arab minority, are deemed unacceptable to some of the coalition’s hard-right members.In the meantime, Mr. Netanyahu, who remains caretaker prime minister, is doing all he can to upend the agreement. 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 that time, his party has promised to pile pressure on right-wing members of the alliance to jump ship, telling them that they have sold out by aligning themselves with leftist and Arab lawmakers.If Mr. Netanyahu fails to persuade enough opponents, it will spell the end — at least for now — of his run at the pinnacle of Israeli politics, the longest tenure of any Israeli prime minister. Either way, he leaves a lasting imprint on Israeli life, and will likely seek to retain significant influence as leader of the opposition.Prime Minister Benjamin Netanyahu arriving at the Knesset on Sunday.Pool photo by Yonatan SindelThe presence of Mr. Bennett at the threshold of power is testament to how Mr. Netanyahu has helped shift the pendulum of Israeli politics firmly to the right..css-1xzcza9{list-style-type:disc;padding-inline-start:1em;}.css-3btd0c{font-family:nyt-franklin,helvetica,arial,sans-serif;font-size:1rem;line-height:1.375rem;color:#333;margin-bottom:0.78125rem;}@media (min-width:740px){.css-3btd0c{font-size:1.0625rem;line-height:1.5rem;margin-bottom:0.9375rem;}}.css-3btd0c strong{font-weight:600;}.css-3btd0c em{font-style:italic;}.css-w739ur{margin:0 auto 5px;font-family:nyt-franklin,helvetica,arial,sans-serif;font-weight:700;font-size:1.125rem;line-height:1.3125rem;color:#121212;}#NYT_BELOW_MAIN_CONTENT_REGION .css-w739ur{font-family:nyt-cheltenham,georgia,’times new roman’,times,serif;font-weight:700;font-size:1.375rem;line-height:1.625rem;}@media (min-width:740px){#NYT_BELOW_MAIN_CONTENT_REGION .css-w739ur{font-size:1.6875rem;line-height:1.875rem;}}@media (min-width:740px){.css-w739ur{font-size:1.25rem;line-height:1.4375rem;}}.css-9s9ecg{margin-bottom:15px;}.css-16ed7iq{width:100%;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;padding:10px 0;background-color:white;}.css-pmm6ed{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;}.css-pmm6ed > :not(:first-child){margin-left:5px;}.css-5gimkt{font-family:nyt-franklin,helvetica,arial,sans-serif;font-size:0.8125rem;font-weight:700;-webkit-letter-spacing:0.03em;-moz-letter-spacing:0.03em;-ms-letter-spacing:0.03em;letter-spacing:0.03em;text-transform:uppercase;color:#333;}.css-5gimkt:after{content:’Collapse’;}.css-rdoyk0{-webkit-transition:all 0.5s ease;transition:all 0.5s ease;-webkit-transform:rotate(180deg);-ms-transform:rotate(180deg);transform:rotate(180deg);}.css-eb027h{max-height:5000px;-webkit-transition:max-height 0.5s ease;transition:max-height 0.5s ease;}.css-6mllg9{-webkit-transition:all 0.5s ease;transition:all 0.5s ease;position:relative;opacity:0;}.css-6mllg9:before{content:”;background-image:linear-gradient(180deg,transparent,#ffffff);background-image:-webkit-linear-gradient(270deg,rgba(255,255,255,0),#ffffff);height:80px;width:100%;position:absolute;bottom:0px;pointer-events:none;}.css-uf1ume{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-pack:justify;-webkit-justify-content:space-between;-ms-flex-pack:justify;justify-content:space-between;}.css-wxi1cx{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;-webkit-align-self:flex-end;-ms-flex-item-align:end;align-self:flex-end;}.css-12vbvwq{background-color:white;border:1px solid #e2e2e2;width:calc(100% – 40px);max-width:600px;margin:1.5rem auto 1.9rem;padding:15px;box-sizing:border-box;}@media (min-width:740px){.css-12vbvwq{padding:20px;width:100%;}}.css-12vbvwq:focus{outline:1px solid #e2e2e2;}#NYT_BELOW_MAIN_CONTENT_REGION .css-12vbvwq{border:none;padding:10px 0 0;border-top:2px solid #121212;}.css-12vbvwq[data-truncated] .css-rdoyk0{-webkit-transform:rotate(0deg);-ms-transform:rotate(0deg);transform:rotate(0deg);}.css-12vbvwq[data-truncated] .css-eb027h{max-height:300px;overflow:hidden;-webkit-transition:none;transition:none;}.css-12vbvwq[data-truncated] .css-5gimkt:after{content:’See more’;}.css-12vbvwq[data-truncated] .css-6mllg9{opacity:1;}.css-qjk116{margin:0 auto;overflow:hidden;}.css-qjk116 strong{font-weight:700;}.css-qjk116 em{font-style:italic;}.css-qjk116 a{color:#326891;-webkit-text-decoration:underline;text-decoration:underline;text-underline-offset:1px;-webkit-text-decoration-thickness:1px;text-decoration-thickness:1px;-webkit-text-decoration-color:#326891;text-decoration-color:#326891;}.css-qjk116 a:visited{color:#326891;-webkit-text-decoration-color:#326891;text-decoration-color:#326891;}.css-qjk116 a:hover{-webkit-text-decoration:none;text-decoration:none;}Under Mr. Netanyahu’s watch, the Israeli-Palestinian peace process collapsed, and tensions between Jews and Arabs inside Israel peaked in May when unrest swept across mixed Jewish-Arab cities during the latest Gaza war.By forging an electoral pact between far-right parties, which later helped them win elected office, Mr. Netanyahu also helped accelerate the impact of the far right on Israeli society and media debates.Against this backdrop, he nevertheless defied expectations and convention by negotiating diplomatic agreements with four Arab countries, subverting assumptions that Israel could make peace with Middle Eastern states only once a final deal with the Palestinians had been made.Israeli right-wing supporters demonstrated against the formation of new government on Sunday.Sebastian Scheiner/Associated PressHe fostered a strong bond with former President Donald J. Trump, who gave Israel several diplomatic victories, shifting the American Embassy to Jerusalem from Tel Aviv, shuttering an American consulate that dealt with Palestinian issues, closing the Palestinian mission in Washington and ripping up an Obama-era deal with Iran.The recent impasse in Israeli politics is also a result of Mr. Netanyahu’s divisive decision to remain in office despite being on trial for corruption.By doing so, his critics argued, he undermined democratic norms, and by attacking the judges in his case, he risked undercutting the rule of law.Mr. Netanyahu denied the charges, and said he had the right to remain in office to defend himself against what he presented as a backdoor coup attempt.But many even in his own base disagreed, leading to a political deadlock in which Mr. Netanyahu retained just enough support to remain in power but not enough to form a stable government — leading to the four inconclusive elections in the past two years, most recently in March.A desire to avoid a fifth election was what ultimately prompted Mr. Bennett to abandon Mr. Netanyahu’s right-wing camp and ally with rivals who, like Mr. Lapid, do not share most of his long-term political vision.If Parliament confirms his government, Mr. Bennett will start his term just as a new president, Isaac Herzog, begins his. Mr. Herzog, a former leader of the centrist Labor party, was elected president by lawmakers on Wednesday. He will assume office in July, and perform the largely ceremonial role for the next seven years. Isaac Herzog with Yariv Levin, speaker of the Knesset.Pool photo by Ronen ZvulunMr. Bennett’s government, if it passes the confidence vote in Parliament, may fall far earlier.Should it collapse, some analysts believe Mr. Lapid may emerge with more credit than Mr. Bennett. While Mr. Bennett gets the first go 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.”Adam Rasgon, Isabel Kershner, Gabby Sobelman and Carol Sutherland contributed reporting. More