Israeli Prime Minister Benjamin Netanyahu was in a battle for his political survival Wednesday as he remained neck-and-neck with his main challenger, Benny Gantz, after an unprecedented repeat election.

With 90 percent of the vote officially counted, the centrist Blue and White party led by former military chief Gantz edged out Netanyahu’s right-wing Likud, according to the Central Elections Committee.

Avigdor Lieberman, the election’s seeming political kingmaker, said he would call for a secular “liberal” unity government with the backing of his far-right Yisrael Beitenu party — without the religious and ultra-Orthodox allies the prime minister has long relied upon.

Without the former defense minister’s endorsement, both parties appear to have fallen well short of securing a parliamentary majority with their prospective ideological allies.

“The conclusion is clear, everything we said throughout the campaign is coming true,” Lieberman said outside his home in the West Bank settlement of Nokdim.

“There is one and only option: a national unity government that is broad and liberal and we will not join any other option.”

Gantz, 60, has ruled out sitting with Netanyahu’s Likud at a time when the prime minister is expected to be indicted soon on corruption charges.

Netanyahu, 69, the longest-serving leader in Israeli history, suffered one of the biggest defeats of his political career in April when his Likud, along with its right-wing and religious allies, won a majority, but he failed to form a coalition and opted for a second election.

He had desperately sought an outright majority with his hard-line and ultra-Orthodox allies.

“Netanyahu needs an overall majority in the Knesset to assure him not only political power, but also legal immunity, or at least the possibility of being able to ask for parliamentary immunity in the face of possible indictments,” Yoav Tenembaum, a lecturer in diplomacy at Tel Aviv University and a political commentator, told The Post.

Hoarse after days of intense campaigning, Netanyahu spoke before supporters early Wednesday and said he was prepared for negotiations to form a “strong Zionist government.”

He appeared to hint at being open to forming a national unity government, but did not specifically say so.

In his speech to supporters in Tel Aviv, Gantz called for a “broad unity government” but cautioned that he was still awaiting final results.

“We will act to form a broad unity government that will express the will of the people,” Gantz said. “We will begin negotiations and I will speak with everyone.”

Tenembaum noted that the Blue and White party has insisted on a precondition for a national unity government in any event — that “it should be formed without Netanyahu due to the possible indictments against him.”

He added: “A situation might emerge in which there is a deadlock as neither the Likud nor Blue and White enjoy the support of 61 MKs and then the president of Israel, Reuven Rivlin, adopts an active role in trying to bring about a national unity government.”

Meanwhile, the mainly Arab Joint List alliance was set to become the third-largest bloc in parliament with 12 seats, according to local reports.

That could put the Arab parties in a position to block Netanyahu from staying in power if they decide to break with precedent and endorse Gantz for prime minister.

Israel’s Arab parties have traditionally not endorsed anyone for the job.

“The main difference in this vote is the turnout among Arab citizens,” Joint List leader Ayman Odeh told journalists outside his home in Haifa on Wednesday.

“There’s no doubt that this is what made the difference. Without that, Netanyahu would already be prime minister,” he added.

With Post wires