Israeli elections tonight produced the tightest of races with early television exit polls putting Tzipi Livni, the centrist foreign minister, narrowly ahead of the rightwing opposition leader Binyamin Netanyahu.

Polls from three main television stations, broadcast moments after voting closed, all put Livni's Kadima party ahead by two seats, but they also predicted that rightwing parties had fared best overall. Livni was predicted as winning either 29 or 30 seats in the 120-seat Knesset.

Avigdor Lieberman, the far-right leader, came in third, ahead of Ehud Barak, the Labour leader and defence minister, whose party was headed for one of its worst election results.

If the exit polls are accurate, and in the past they have not always been reliable, it suggests a long, drawn-out period of negotiations to form a coalition. Even if Livni emerges with the largest party she may not become prime minister if the rightwing parties can together muster a larger coalition.

Both Netanyahu and Livni cast their votes early and urged Israel's 5.3 million eligible voters to go to the polls for what was one of the closest election races in recent years.

"I have just done what I want every citizen in Israel to do: first of all to get out of the house, rain or no rain, cold or hot, go out, go to the polling station, go into the booth, close your eyes, and vote," Livni said, after casting her ballot in Tel Aviv.

Netanyahu voted in Jerusalem and then travelled to the southern city of Be'er Sheva, to emphasis his security credentials in a city hit by rockets during last month's war in Gaza. "I will do everything so that our enemies won't provoke us, won't think we're weak, won't rain down ... their rockets," he said.

Under Israel's proportional representation system no one party is likely to win a majority, meaning weeks of negotiation will now follow to form a coalition government. Next week the Israeli president, Shimon Peres, will call on the leader of the party he thinks most likely to form a coalition, regardless of whether that is the largest party, and give him or her 42 days to complete the task.

These early elections were triggered last autumn when the current prime minister, Ehud Olmert, said he would resign in the wake of several corruption investigations. He stays on as a caretaker prime minister until the new cabinet is formed.

For months leading up to the election Netanyahu had been comfortably ahead in the polls, but his lead narrowed sharply in the final days. In part the rise of far-right leader Lieberman took votes away from the Likud party, although the rightwing as a whole looked set to dominate. But many voters said they were undecided until they walked into the polling booth.

"I am by instinct a leftist but I think the leftists failed completely and it is time to recognise that we need really to be strong and somewhat aggressive in the way in which we live or we have no hope," said Herb Alexander, a psychology professor voting in Talbiyeh, in west Jerusalem.

Gil Erlich, 28, a psychologist, had voted Labour in the past but today voted for Livni's Kadima party, saying he hoped to keep out a rightwing government. "The main issue is the matter of rightwing versus leftwing," he said. "It doesn't really matter how many votes Bibi or Tzipi gets. What is really important is who builds the coalition."