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 Mr 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 Mr 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," Mr Netanyahu, 69, told cheering supporters in a late-night speech at Likud headquarters.
He tempered that with a 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 are expected by Friday, though the provisional results showed 65 of the Knesset's 120 seats would go to the right-wing bloc of parties led by Netanyahu, against a total of 55 seats for center-left factions.
A victory would make Mr Netanyahu the longest-serving prime minister in Israel's 71-year history. He said he had already begun talks with prospective coalition allies.
In power since 2009, and having led the country for a total 13 years including his first term in the 1990s, the corruption allegations have meant he was fighting for his political survival.
Mr Gantz, a 59-year-old former general, earlier also claimed victory citing preliminary exit polls published soon after voting ended on Tuesday that showed his party had won more seats than Likud.
However, a clearer picture emerged by Wednesday morning as the results began streaming in.
During the campaign, the rival parties accused each other of corruption, fostering bigotry and being soft on security.
Mr Netanyahu highlighted his close relationship with US President Donald Trump, who delighted Israelis and angered Palestinians by recognizing Jerusalem as Israel's capital in 2017 and moving the American Embassy to the holy city last May.
Two weeks before the election, Mr Trump signed a proclamation, with Mr Netanyahu at his side at the White House, recognizing 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, Mr Netanyahu further alarmed Palestinians by pledged 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.
Commenting on the election, Palestinian chief negotiator Saeb Erekat said Israelis had voted to preserve the status quo.
"They have said no to peace and yes to the occupation," he said.
The last round of US-brokered peace talks between Israel and the Palestinians collapsed in 2014.
Mr Trump is expected to release his administration's long-awaited Middle East peace plan after the election. Any concession to Palestine would likely bring objections from Mr Netanyahu's far-right coalition allies.