JERUSALEM — Israeli Prime Minister Benjamin Netanyahu and his main challenger, former military chief Benny Gantz, were locked in a neck and neck race Tuesday as exit polls showed no clear winner in an election that was seen as a referendum on the long-serving leader.

With final results still hours away, both men declared victory, though Netanyahu appeared to have better prospects of forming a coalition with smaller ideological allies. Still, the results appeared to be a setback for Netanyahu as they failed to give him the decisive victory he had sought. The 69-year-old prime minister’s fate is clouded by a series of corruption investigations.

Two Israeli TV stations showed Gantz’s Blue and White Party with a narrow lead over the Likud. Channel 12 TV had Blue and White with 37 seats to Likud’s 33 seats, while Kan TV put Blue and White ahead 37-36. Channel 13 had the two parties deadlocked with 36 seats apiece.

Because both parties are far short of a majority in the 120-seat parliament, they would have to search for smaller ideological allies to cobble together a majority.

The Kan and Channel 13 polls projected Likud and its hard-line allies controlling a slight majority of seats, while a Channel 12 poll showed Netanyahu and Gantz’s blocs with 60 seats apiece.

Early on Wednesday, Gantz addressed a raucous crowd. “Elections have losers and elections have winners. And we are the winners,” he told supporters.

He vowed to change the tone of Israel’s divisive political system and “be the prime minister of everyone, not just the ones who voted for me.”

Claiming to represent the largest party, Gantz urged President Reuven Rivlin to give him the opportunity to form the next government. As president, Rivlin is responsible for choosing the prime minister after consulting with party leaders and deciding who has the best chance of cobbling together a coalition.

Netanyahu, who was set to address his supporters later Wednesday, said in a statement that his right-wing bloc won a “clear victory.”

Israeli exit polls are notoriously imprecise, meaning the final results could still swing in either direction. Official results weren’t expected until Wednesday morning.

The final results will depend on the performance of several small parties, including the Arab Balad party and the ultranationalist “New Right,” that were on the cusp of winning the needed 3.25 percent of the votes to enter parliament. If any of them fail to cross the threshold, the makeup of the next coalition could be dramatically affected.

Clouded by looming corruption indictments, Netanyahu is seeking a fourth consecutive term and a fifth overall, which would make him Israel’s longest-serving leader, surpassing founding father David Ben-Gurion.

The election has emerged as a referendum on his 13 years in power, with the existential questions facing Israel rarely being discussed in the campaign.

Netanyahu has been the dominant force in Israeli politics for two decades. His campaign has focused heavily on his friendship with President Donald Trump and his success in cultivating new allies, such as China, India and Brazil.

But the corruption scandals have created some voter fatigue, and in recent days Netanyahu has vowed to annex Jewish West Bank settlements if re-elected — a prospect that could doom already-slim hopes of establishing a Palestinian state alongside Israel, which he has wavered on.

In Gantz, he encountered the rare opponent who can match his security credentials.

Along with two other former military chiefs on his ticket, Gantz has attacked Netanyahu for failing to halt rocket fire from the Hamas-ruled Gaza Strip.

Gantz, who has been vague on key policy fronts, has presented himself as a clean, scandal-free alternative to Netanyahu.