With around 70 percent of votes counted in Israel's election, Prime Minister Benjamin Netanyahu's Likud party was leading early Wednesday with 23.73 percent, the Central Elections Committee said.
His nearest rival, the centre-left Zionist Union was trailing with 19.06 percent, the committee's website said, without translating the percentages into parliamentary seats won.
Netanyahu had earlier claimed victory in elections Tuesday and the initial results seemed to ensure him a third straight term, likely to further strain relations with the Palestinians.
Exit polls published on two TV stations as polling stations closed had given Likud and Zionist Union 27 seats each in the 120-member parliament.
A third poll gave Likud a one-seat lead.
"Against all odds we achieved a great victory for the Likud. We achieved a great victory for the national camp under the leadership of the Likud. We achieved a great victory for our people of Israel!" Netanyahu told cheering supporters at campaign headquarters in Tel Aviv.
"Now we have to build a strong and stable government," he added.
But Herzog, 54, insisted he was still in the race to form the next government.
"Everything is open," he told activists in Tel Aviv.
"I intend to make every effort to build a real social government in Israel."
The result of the vote is likely to have implications for prospects for new Middle East peace talks and Israel's troubled relations with its US ally.
In a late appeal to the far-right ahead of the polls, Netanyahu ruled out the establishment of a Palestinian state if reelected, effectively reneging on his 2009 endorsement of a two-state solution.
Herzog has repeatedly called for the creation of a Palestinian state alongside Israel.
Netanyahu made a last-minute call on his supporters to go to the polls to counter a high turnout among Arab Israelis.
"The rule of the rightwing is in danger. Arab voters are going to the polls in droves!" he said in a video on Facebook. "Go to the polling stations! Vote Likud!"
The main Arab parties took third place with 13 seats after joining forces to challenge the premier, according to exit polls.
Likud activists at a temporary headquarters set up in a Tel Aviv convention hall danced in celebration at the late surge.
"This is a great victory, almost a miracle," Netanyahu confidant Ofir Akunis told AFP.
"Now we need to focus on building the new government. We will talk to every party, old and new."
- Late catch-up -
His Likud had been trailing the Zionist Union by up to four seats in surveys in the week leading up to the vote, which was seen as a referendum on his premiership.
Experts said Netanyahu looked like the most likely party leader to be asked by President Reuven Rivlin to form a government after the official results, which are expected in the coming days.
"Netanyahu has done it. He has managed to catch up in the final lap," said Claude Klein, a specialist in constitutional law at Jerusalem's Hebrew University.
"On paper, Isaac Herzog has no chance of putting together a majority which would depend on the support of the Arab List which includes openly anti-Zionist MPs."
Under Israel's electoral system, the prime minister is not the head of the party that gains the most seats but whoever can build a coalition commanding a majority of at least 61 seats in parliament.
Moshe Kahlon, once a popular minister under Likud, could find himself in the position of kingmaker after exit polls predicted his centre-right Kulanu party won 10 seats.
Kahlon talked to both Netanyahu and Herzog "and told them both he'd make his decision based on the final results," his spokesman said.
Israel Democracy Institute president Yohanan Plesner said that although Netanyahu had made a remarkable recovery the outcome was still not certain and in terms of overall voting the centre-left parties were forecast to win 57 seats while the right and religious parties would get around 54.
"In the middle we have Kahlon, who is not committed to either bloc," he said.
"I think the clearest political outcome is that he's going to be the kingmaker and it really depends on how he decides to play his cards."
- 'Serious problems' -
Some 5.8 million people were eligible to vote, with 25 parties vying for the Knesset.
Turnout was 71.8 percent, up from 67.8 percent in 2013.
"Israel has serious problems, and only a rightwing leader can handle them," said a Jerusalem voter who gave his name as Yehoshua, pledging support for Netanyahu.
But others took a different view.
"I'd like to see Netanyahu disappear for many, many years. The most important issue is relations with the Palestinians," said Shulamit Laron.
Netanyahu put security at the forefront of his campaign, arguing he is the only one capable of protecting Israel from an Iranian nuclear threat and vowing never to allow the Palestinians to establish a capital in east Jerusalem.
The Palestinians vowed to step up their diplomatic campaign for statehood.
"It is clear that Prime Minister Benjamin Netanyahu will form the next government, so we say clearly that we will go to the International Criminal Court in the Hague and we will speed up, pursue and intensify" all diplomatic efforts, chief negotiator Saeb Erakat told AFP.