By Jeremy Bowen
BBC Middle East Editor, Jerusalem
You could see when Ehud Olmert was making his victory speech that he was delighted that he was going to be prime minister.
Ehud Olmert has to balance many conflicting demands
He was not going to let the fact that Kadima had six or seven fewer seats than he had expected ruin his night.
Mr Olmert comes from one of the founding families of the Israeli right, and when he was a young politician he was known as one of the "princes of the Likud".
He left Likud with Ariel Sharon at the end of last year. The election has crushed his old party and its leader - his long time rival Binyamin Netanyahu - so now the 60-year-old prince, at last, has the crown.
Unlike Ariel Sharon, who was careful about what he said to preserve his freedom to manoeuvre, Mr Olmert has been very open about what he wants to achieve.
During the election campaign he said that during the next four years he would set Israel's border with the Palestinians.
But before he can do that, he has to form a government, which means building a coalition. After a couple of weeks of negotiations, he might start to rue the fact that Kadima does not have those missing six or seven seats.
The Israeli parliament, the Knesset, has 120 seats. He needs the votes of at least 61 members. Kadima has 28.
Big challenges, and crises, lie ahead for Ehud Olmert. Ariel Sharon made Israelis feel safe in a crisis. Will Ehud Olmert measure up?
Labour, the obvious junior partner, has 20. Its leader Amir Peretz will be able to extract a high price for his support.
He ran on a promise of helping the poor. He might demand the finance ministry for Labour and the job of deputy prime minister, with responsibility for social and economic policy, for himself.
There is also the left-wing party Meretz, which has 4 seats.
But after that it gets more difficult. He will have run out of natural allies for a process that involves giving up occupied territory.
Settlers could be a huge obstacle to Mr Olmert's plans
The Pensioners' party, which unexpectedly won seven seats, could help him out. He will get its support if he agrees to improve pensions and medical care for old people.
Then Mr Olmert might need to turn to the religious parties - or a possible deal with Israel Beiteinu, a right-wing party led by Avigdor Lieberman, a controversial Russian immigrant who wants some towns where Israel's Arab citizens live to be transferred to a future Palestinian state.
It is more messy than Mr Olmert would have liked. Buying the support of coalition partners will, at the very least, slow him down. And that is not the end of it.
Mr Olmert does not have an overwhelming mandate. A substantial minority of Israelis voted against his plans, which include an intention to strengthen Israel's hold on Jerusalem and the big Jewish settlements by abandoning remote ones.
The Israeli settler movement used to be the most powerful and dynamic political force in the country. It was badly weakened when Ariel Sharon ignored its wishes and withdrew soldiers and settlers from the Gaza Strip last August.
But when the Israeli authorities wanted to destroy nine houses which it said were illegally built in a settlement on the West Bank in January, it had to deploy thousands of police to control tens of thousands of demonstrators.
What will happen when Israel, as expected, tells 60,000 settlers that they will lose their homes?
And then there are the Palestinians. Today the new Palestinian cabinet, formed by Hamas, has been sworn in.
Mr Olmert will not talk to Hamas unless it drops some of its most deeply held beliefs. But even so it will be hard to ignore it.
Mr Olmert's border plan is an Israeli solution to an Israeli problem. It affects Palestinian lives deeply, but they have not been consulted.
In his victory speech Mr Olmert talked about the desirability of having a Palestinian partner. Could there be scope for talks with the Palestinian president, Mahmoud Abbas? One Israeli analyst suggested they should start in secret while Israel encourages the collapse of the Hamas administration.
Mr Olmert might be able to fix a border that Israelis approve of. Getting it rubber stamped by the rest of the world would be much harder.
There are more than 50 years of international decisions, treaties, resolutions and peace plans about the conflict.
One of the most important is UN Security Council resolution 242, which was passed after Israel captured the West Bank in the 1967 Middle East war. It emphasises the "inadmissibility of acquisition of territory by war and the need to work for a just and last peace in which every state in the area can live in security".
Interpretations of 242 vary, but the UN believes that unilaterally setting a border with the Palestinians would violate it, because Israel would be annexing land captured by war in 1967.
At a time when the UN is an important part of the way that the United States and other Western powers deal with international crises, it would not be easy for them to turn a blind eye to 242.
Big challenges, and crises, lie ahead for Ehud Olmert. Ariel Sharon made Israelis feel safe in a crisis. Will Ehud Olmert measure up? If he cannot, it will be even harder for him.
His plan might, with some luck, buy some quiet for Israelis. But peace is not in sight.