Israeli Prime Minister Benjamin Netanyahu appeared poised to win the country’s national election and secure a record fifth term in office Wednesday after months of scrambling to remain in power by striking deals with far-right extremists, promoting conspiracy theories, sidling up to authoritarian leaders and promising new restrictions on Palestinian rights. The race was incredibly tight and Netanyahu still faces the task of cobbling together a coalition government. His Likud party appears to have won just over 26 percent of the vote with nearly all the ballots counted, giving Netanyahu a clearer path than any other party leader to building a parliamentary majority. Israel President Reuven Rivlin will very likely choose him to form the next government once all the votes are in. Netanyahu began his fifth reelection campaign with a clear road to victory, facing a fractured opposition and looking like a strong bet to become Israel’s longest-serving prime minister. But that soon changed. And as his reelection came under threat, he led a campaign that stoked division to save himself. Weeks before the vote, two of Netanyahu’s challengers, including former military officer Benny Gantz, created a centrist opposition party that soon was neck and neck with Netanyahu’s Likud party in the polls. Long-running corruption investigations into Netanyahu then reached their climax with Israel’s attorney general announcing he would soon formally indict the prime minister. Facing a close race and the looming indictment, Netanyahu exploited every opportunity to rally his supporters to put him over the finish line, no matter the cost.

Associated Press Benjamin Netanyahu’s career is pockmarked with scandals. But his looming indictment, a first for a sitting Israeli prime minister, is the most serious yet.

Although he has a history of eking out election victories by playing on voters’ fears, such as warning in 2015 that Israel’s Arab citizens were casting their ballots “in droves,” Netanyahu reached new lows during this year’s campaign. On Election Day, his party reportedly distributed around 1,200 hidden cameras to observers in Arab communities in what critics described as a deliberate act of voter suppression. Prior to that, Netanyahu reached an agreement with racist and homophobic far-right parties in February to prop up his reelection bid, promising one party key government positions in exchange for supporting his premiership. One group, Jewish Power, has its roots in a violent anti-Muslim movement that the U.S. government deemed a terrorist organization. A prominent Israeli correspondent likened the agreement to a U.S. president striking a deal with the Ku Klux Klan. The deal with the far right drew widespread condemnation both in Israel and abroad, earning rare rebukes even from conservative, staunchly pro-Israel organizations such as the American Israel Public Affairs Committee lobbying group. The Anti-Defamation League said the deal “legitimized” the party’s “hate-filled rhetoric,” and Gantz accused the prime minister of sacrificing his dignity. But Netanyahu was only getting started. The prime minister’s career is pockmarked with scandals: In his first term as prime minister, he was investigated for influence peddling and improperly accepting foreign gifts and contributions. But the looming indictment, a first for a sitting Israeli prime minister, is the most serious yet. In the final months of his campaign, Netanyahu relentlessly pushed to convince voters that he was synonymous with the Israeli state and that the corruption scandals circling his family were leftist conspiracies. Borrowing the same rhetoric that U.S. President Donald Trump and radical right-wing populist leaders use to dismiss the press and avoid accountability, he painted nearly anyone who opposed him as a leftist — even the centrist Gantz, whose campaign video boasts about the number of alleged terrorists he killed during an Israeli military offensive in Gaza.

Associated Press A billboard in Israel shows Donald Trump and Benjamin Netanyahu shaking hands. Netanyahu has used his friendship with Trump as proof of his influence.