Critics have accused Tzipi Livni of lacking political experience
Israeli Foreign Minister Tzipi Livni has won the leadership of the governing Kadima party, putting her on track to succeed Ehud Olmert as prime minister.
Ms Livni beat Transport Minister Shaul Mofaz by just 431 votes, or 1.1%, the central electoral commission said.
In a victory speech, Ms Livni announced that she wanted to form a new cabinet "as quickly as possible in the face of the serious threats" facing Israel.
She has 42 days to do so, during which time Mr Olmert remains prime minister.
He announced he would step down in July after facing growing pressure over multiple corruption investigations.
The senior Palestinian Authority negotiator, Saeb Erekat, said he hoped the result would lead to a return to stability.
The militant Hamas organisation, which controls the Gaza Strip, said it expected no change in Israel's policy towards the Palestinians if Ms Livni did become prime minister.
The BBC's Tim Franks in Jerusalem says that for much of Wednesday night, Ms Livni's supporters in the Kadima party cheered at what they believed had been an emphatic victory, predicted by a series of exit polls on Israeli TV.
Mr Olmert phoned his foreign minister to congratulate her and promise his full co-operation after she appeared on track to win with about 48% of the vote. Then the balloon slowly deflated as the results rolled in, our correspondent says.
According to the final results released by Kadima, Ms Livni won the election with 43.1%, or 16,936 votes. Mr Mofaz, a former defence minister and chief of staff of the Israeli military, came in a close second with 42%, or 16,505 votes.
The two other candidates, Interior Minister Meir Sheetrit and Public Security Minister Avi Dichter, lagged far behind with 8.4% and 6.5% respectively.
Mr Mofaz's supporters initially warned that they might lodge an appeal against the result over alleged irregularities at some polling stations, but he later telephoned Ms Livni to formally admit defeat and congratulate her, Israeli Army Radio reported.
Israelis react to Tzipi Livni's win
In a victory speech early on Thursday morning, Ms Livni said that she would seek to form a new coalition government "as quickly as possible" and called for party unity.
"All the people who came to vote today expressed what they wish to happen in this country," she said. "The national responsibility [bestowed] by the public brings me to approach this job with great reverence."
If she can form a fresh governing coalition within the next six weeks, Ms Livni will become Israel's first woman prime minister since Golda Meir stepped down in 1974.
Our correspondent says that will be no easy task, and if it were to end in failure, general elections will follow in a further three months.
The leader of a key coalition partner, the ultra-Orthodox Shas party, quickly laid out its conditions for taking part in a new government, including ruling out any negotiations on the future of Jerusalem.
"If Livni wants a government, she needs to comply with our demands," Eli Yishai said.
Ms Livni is seen as less hawkish than Mr Mofaz when it comes to the Palestinians and to dealing with Iran's nuclear ambitions.
Critics say Ms Livni, a former lawyer and Mossad agent, also lacks political experience.
WHAT HAPPENS NEXT
Ehud Olmert formally resigns as prime minister and his cabinet resigns with him
President consults parties to pick a Knesset member to form a new cabinet - expected to be the Kadima leader
The MK has 42 days to form a coalition acceptable to parliament
If no coalition is formed, another MK may be asked to try to form a government, or a general election may be called
If a general election is called, it must be held within 90 days
Mr Olmert remains caretaker prime minister until the Knesset approves a new government
Her supporters say she represents a break with the past. Ms Livni is untainted by the kind of allegations of corruption and bribery that led to Mr Olmert's resignation and have damaged the reputation of Israeli politics.
"[She] is a good choice as far as Israel's foreign relations are concerned, but there is still the tension with Iran. I am not so sure how much experience she has for such matters and if she will be able to take the right decisions," said Shmuel Sandler, professor at the Begin-Sadat Centre for Strategic Studies.
"She looks like 'Mrs Clean'... but she will still have to form a coalition," he told the Reuters news agency. "It is very difficult to predict whether she will be a strong prime minister."
Kadima was formed three years ago when former Prime Minister Ariel Sharon split from the centre-right opposition party, Likud, to draw together support from left and right for his policy of unilateral withdrawals from the Gaza Strip and parts of the West Bank.
But its poll ratings fell after a stroke left Mr Sharon in a coma.
His successor, Mr Olmert, faced strong criticism of his handling of the 2006 Israel-Lebanon war and he was investigated in several corruption scandals.
Polls now suggest Likud could win a potential general election, which would take place if a coalition government cannot be formed in the wake of the Kadima leadership vote.
The Kadima election comes as the US government is continuing its push for an Israeli-Palestinian peace deal before President George W Bush leaves office in January.
Mr Olmert and Palestinian Authority President Mahmoud Abbas held talks on Tuesday. An Israeli spokesman said the two would continue to meet until a new government was sworn in.
This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.