Israel Election Results: Benjamin Netanyahu with his wife Sara. (Reuters)

Prime Minister Benjamin Netanyahu has won the Israeli national election, securing a record fifth term in office despite running neck in neck with his challenger Benny Gantz, the country's three main television channels said on Wednesday.

With 97 percent of the votes counted, neither of the candidates' parties had captured a ruling majority, but Netanyahu was clearly in a strong position to form a coalition government with other right-wing factions that have backed him.

The closely contested race was widely seen in Israel as a referendum on Netanyahu's character and record in the face of corruption allegations. He faces possible indictment in three graft cases, and has denied wrongdoing in all of them.

The veteran right-wing leader's Likud party and Gantz's new centrist Blue and White party both won 35 seats, according to the Knesset website and the Israeli TV channels. That would mean a five-seat gain for Likud.

"It is a night of colossal victory," the 69-year-old Netanyahu told cheering supporters in a late-night speech at Likud headquarters, while cautioning that a "long night and possibly day" lay ahead awaiting official results.

Fireworks flared behind him as his wife Sara applauded and kissed him. "He's a magician," the crowd chanted.

Final results were expected by Friday.

If he wins, Netanyahu, 69, will be on track to be the longest-serving prime minister in Israel's 71-year history. Netanyahu said he had already begun talks with prospective coalition allies.

Netanyahu, in power consecutively since 2009, has been fighting for his political survival. He faces possible indictment in three graft cases, and has denied wrongdoing in all three.

Rival Gantz, 59, earlier had also claimed victory, citing preliminary exit polls that were published soon after voting ended on Tuesday showed his party had won more seats than Likud.

"We are the victors," said Gantz, a former military chief fighting his first election. "We want to thank Benjamin Netanyahu for his service to the nation."

Despite both men claiming victory on Tuesday night, a clearer picture emerged by Wednesday morning as the results began streaming in, painting Netanyahu as the winner.

Netanyahu Highlights Trump Ties

During the campaign, the rival parties accused each other of corruption, fostering bigotry and being soft on security.

Netanyahu highlighted his close relationship with US President Donald Trump, who delighted Israelis and angered Palestinians by recognising Jerusalem as Israel's capital in 2017 and moving the American Embassy to the holy city last May.

Two weeks before the election, Trump signed a proclamation, with Netanyahu at his side at the White House, recognising Israeli sovereignty over the occupied Golan Heights captured from Syria in the 1967 Middle East war.

In a rare turn during the race towards the Israeli-Palestinian conflict, Netanyahu further alarmed Palestinians by promising to annex Jewish settlements in the occupied West Bank if re-elected. Palestinians seek a state there and in the Gaza Strip, with East Jerusalem as its capital.

During the campaign, Gantz said a government under his stewardship would pursue peace, but stopped short of committing to the establishment of a Palestinian state.

Commenting on the election, Palestinian chief negotiator Saeb Erekat said: "Israelis have voted to preserve the status quo. They have said no to peace and yes to the occupation".

The last round of US-brokered peace talks between Israel and the Palestinians collapsed in 2014.

Trump is expected to release his administration's long-awaited Middle East peace plan after the election. If it includes Israeli concessions to the Palestinians, Netanyahu's probable far-right coalition allies will likely object.

A close result in the election would put smaller parties in a powerful position, turning marginal political figures into kingmakers.

Once the votes are tallied, President Reuven Rivlin will ask parties that have won parliamentary seats who they support for prime minister. He will then pick a party leader to try to form a coalition, giving the candidate 28 days to do so, with a two-week extension if needed.