Prime Minister Benjamin Netanyahu claimed victory in Israel's election after exit polls showed he had erased his center-left rivals' lead with a hard rightward shift in which he abandoned a commitment to negotiate a Palestinian state.
Difficult coalition talks still lie ahead, in a politically divided country where no one party has ever won an outright majority in parliament.
Isaac Herzog, Netanyahu's chief opponent and head of the center-left Zionist Union, said "everything is still open" and that he already had spoken to party leaders about forming a government.
But after days in which Zionist Union appeared poised to defeat Netanyahu's Likud, the exit polls late on Tuesday put the two parties in a dead heat. Netanyahu sought to seize the momentum, taking to Twitter to portray the photo finish as a triumph that defied earlier predictions.
Political commentators said Netanyahu seemed to have the easier path to forming a cabinet, with the support of traditional rightist allies - which would put him on course to becoming Israel's longest serving leader. But he would also need the backing of kingmaking centrists, who were non-committal on their future moves after the polls closed.
Netanyahu pulled off the feat with a pitch for ultranationalist votes in the final days of the hard-fought campaign, using tactics that could deepen a feud with the White House.
Netanyahu has focused on Iran's nuclear program and militant Islam. But many Israelis had said they were tiring of the message, and the center-left campaigned on social and economic issues, surging in polls before election day.
An exit poll for Channel 2 TV gave Likud 28 seats and Zionist Union 27 in the 120-member parliament. Channel 10, revising its survey several hours after voting ended, put that margin at 27 seats for Likud to 26 for Zionist Union. Channel 1 had both parties tied at 27.
"Against all odds: a great victory for Likud," a beaming Netanyahu told cheering supporters in a speech at party election headquarters in Tel Aviv. He said he had spoken to leaders of other right-wing parties and urged them to form a "strong and stable" government with him without delay.
"He's a magician, he's a magician," the crowd chanted.
Opinion polls in the run-up to the ballot had shown Zionist Union with a three- to four-seat advantage over Likud, suggesting the public had warmed to Herzog, who won over voters with flashes of wit after enduring being lampooned for his short stature and reedy voice.
An initial count gave Likud a 32-24 seat lead over Zionist Union but that was based on votes from 57 percent of the polling stations. Final results were not expected until later on Wednesday.
A new centrist party, Kulanu, led by former communications minister Moshe Kahlon could tip the scales in coalition talks. After the balloting ended, Kahlon said he did not rule out a partnership with either Likud or Zionist Union.
The exit polls gave right-wing and religious parties about 54 seats, and left-leaning factions, 43 - both figures still short of a governing majority. It may be weeks before the country has a new government, and until then, Netanyahu will remain prime minister.
Turnout was around 72 percent, higher than the last election in 2013.
President Reuven Rivlin to name the candidate he deems best placed to try to form a coalition. The nominee will have up to 42 days to do so.
Rivlin has called for national unity, signaling he favors a government that would pair both Likud and Zionist Union - a partnership Netanyahu rejected during the campaign.
Naftali Bennett, leader of the ultranationalist Jewish Home party, said he had spoken with Netanyahu and agreed to open "accelerated" coalition talks with him.
But Zionist Union could find a lifeline from Kulanu and from Arab parties that united for the first time in a joint list of parliamentary candidates and came in third in the exit polls.
While they are unlikely to join a government, the Arab parties could give a center-left coalition tacit support and create a block against Netanyahu.
If the center-left is to assemble a government, it will also need the support of ultra-Orthodox parties, which the polls said would win 13-14 seats.
Ramping up his bid for right-wing votes, Netanyahu on election day accused left-wing groups of trying to remove him from power by busing Arab-Israeli voters to polling stations, a statement that drew a sharp rebuke from Washington.
Some political rivals accused Netanyahu of racism over the remarks.
The Obama administration has been angry at Netanyahu since he addressed the U.S. Congress two weeks ago at the invitation of Republican lawmakers, to oppose ongoing U.S. nuclear negotiations with Iran.
In the last days of campaigning as he sought to persuade supporters of smaller right-wing parties to "come home" to Likud, Netanyahu promised more building of Jewish settlements. Cautioning that yielding territory would open the way for attacks against Israel by Islamic militants, Netanyahu said the Palestinians would not get their own state if he were re-elected.
Those sweeping promises, if carried out, would further isolate Israel from the United States and the European Union, which believe a peace deal must accommodate Palestinian demands for a state in the occupied West Bank, East Jerusalem and Gaza.
Saeb Erekat, chief Palestinian negotiator in peace talks with Israel that collapsed in April, told Reuters it appeared Netanyahu would form the next government.
Citing the Israeli leader's rejection of a Palestinian state, Erekat said: "Mr. Netanyahu has done nothing in his political life but to destroy the two-state solution."