By Jeremy Bowen
BBC Middle East Editor
A year ago, on a freezing, foggy night in Ramallah, in the occupied West Bank, party officials in the Palestinian election centre could not believe what they were hearing.
The Palestinian vote for Hamas was a slap in the face for Fatah
Hamas was on top. It was hard to tell who was more amazed - Hamas, or Fatah, the other big Palestinian faction.
Hamas people had expected to do well. But their plan was to be the opposition, troublesome as well as loyal. They had not expected to win parliamentary elections to control the Palestinian Authority (PA).
Fatah had not expected to lose. It took both of them months to recover from their January surprise.
Hamas had not won an election to form a government, as the Palestinians do not have a state. The territory that they hope to make into one is under varying degrees of Israeli military occupation.
A legacy of the now defunct peace process of the 1990s is that Israel allows Palestinians to administer some aspects of their lives, like the education system, hospitals and basic policing.
Within the limitations of what was possible, Palestinians voted for Hamas because they were sick of years of corruption and mismanagement by Fatah, and because they believed Fatah's approach to Israel was not working.
A rough ride
Fatah, and its leader Mahmoud Abbas, who remains the elected president of the Palestinians, has recognised Israel and is committed to finding a way to live alongside it.
A majority of Palestinians has never stopped believing that dividing the land between the River Jordan and the Mediterranean Sea into two states, more or less along the boundary that held until the 1967 Middle East war, is their only chance of peace.
Palestinians hoped the world would respect a democratic election
But when they went to vote a year ago, Palestinians felt that the moderation of the 1990s had brought them no closer to independence. They were also exhausted by the armed uprising that started in 2000.
But they wanted to give Fatah a slap - and to send the Israelis a message that they could not expect co-operation while they kept Gaza as what Palestinians often call the world's biggest prison, while also deepening their occupation of the West Bank by expanding Jewish settlements and taking more Palestinian land.
Palestinians may have guessed that a vote for Hamas was a vote for a rough ride.
But there was a sense of desperation, even nihilism among them, and while they knew Israel well enough not to have expected a welcome for Hamas, there was also the hope that the result of a democratic election would be respected by the rest of the world.
Money tap turned off
The Americans, after all, were pushing democracy as the solution to the stagnation, corruption and decay of the Arab world.
But the message from the US, the European Union and the Russians was essentially that you Palestinians can vote for who you like, but if we don't approve of the winner we don't have to deal with them.
Palestinians have protested against the PA's financial meltdown
It turned out to be a very rough year for the Palestinians.
Hamas refused an ultimatum from the outside world to recognise Israel, give up violence and accept previous agreements made by Fatah.
As a result, Israel and the big countries turned off the money tap that had been part of the Palestinians' reward for being part of the peace process in the 1990s.
The PA was in deep financial crisis when Hamas won the election. Afterwards it was much worse.
PA employees, including doctors and teachers did not get paid; hospitals ran out of some medical supplies.
When rockets were fired repeatedly at the Israeli border town of Sderot, and an Israeli soldier was captured in a raid into Israel, the Israeli army started a military offensive in Gaza that lasted for the rest of the year.
In 2006, the UN calculated that 876 Palestinians were killed in the occupied territories and more than 4,000 were wounded. The figures for Israel were 25 dead and 377 wounded.
Fatah was used to being in power, and has found it very hard to adapt to the new set-up.
It still controls big sections of the security forces. Even before the elections, Palestinian society, weakened by the absence of hope about the future, was already splintering under the crushing weight of Israel's military occupation.
Fighting between Hamas and Fatah factions has claimed over 60 lives
Israel pulled its settlers out of Gaza in 2005 but is still, effectively and under international law, the occupying power.
Fatah's resentment at losing, the indignation of supporters of Hamas that their victory was being questioned, and the continuous pressure exerted by Israel generated more violence.
At least 60 Palestinians have died in shoot-outs between Hamas and Fatah supporters.
If any of the bullets had killed prominent leaders it could have tipped into civil war - it still might.
The most significant intervention made by the US in the last few months has been to rush weapons to Mr Abbas for his supporters.
Mr Abbas has been trying to start a dialogue with Israel and to negotiate with the Hamas Prime Minister Ismail Haniya to form a national unity government.
The president's supporters in Western capitals are hoping he can create a new government which will agree a form of words about Israel's existence that will allow them to ease the financial sanctions that were aimed at crippling the Hamas administration.
That is unlikely, or it would have happened already.
Gloomy year ahead
For Palestinians, just as important is stopping the mayhem in the streets.
Some Palestinians are disappointed with the performance of Hamas. Recent polls (not always reliable) suggest that if there was an election tomorrow Fatah would win.
Ismail Haniya says a long-term ceasefire with Israel is possible
The year ahead is gloomy. The rest of the region is locked into its worst crisis in generations - some say the worst of modern times.
Hamas will do all it can to stay in power. Sanctions against it are still in place but more money is coming into the occupied territories through the office of the president.
Hamas takes a long view. It believes that time, and history, are on its side, that the future of the Middle East belongs to Islamists.
For Hamas, secular nationalism - the creed of Fatah and the Palestine Liberation Organisation (PLO) for almost 50 years - has failed, because Palestinians still are not free.
Despite the pressure it has been under, Hamas has stayed with its twin-track strategy of following a political route as well as sticking with what almost every Palestinian views as a legitimate armed struggle.
Its political leaders who are free to speak (mainly in Gaza and abroad, as most of those in the West Bank are in Israeli jails) send out what look like conciliatory statements, offering Israel a long-term ceasefire in return for the establishment of a sovereign Palestinian state in the West Bank, Gaza and East Jerusalem.
The idea, they say, is calm instead of perpetual war. What happens after that would be left to the next generation.
Is Hamas changing?
Israel is not ready to give up the entire West Bank and to allow a Palestinian capital in east Jerusalem. Even if it was, mainstream Israelis and their friends abroad do not have much time for what they view as the weasel words of spokesmen for a terrorist organisation.
Why, they ask, should they trust Hamas not to use a long truce to build up weapons? What about the Hamas charter, written in religious language, which sees the entire land of Palestine as an Islamic possession, with no room for Israel?
Hamas is known for espousing conservative Islamic values
Why give Hamas a base from which they could try to destroy Israel? Why give Hamas the victory a state would represent in return for nothing more than an airy promise that they will not kill Jews?
Their caution is understandable. In the last 11 years or so Hamas has killed hundreds of Israeli civilians.
But what if Hamas is changing, now that it is embracing the complexities of politics as well as the simplicities of the armed struggle?
At the very least it is clear that some of its leaders are moving down the same path towards co-existence that Fatah and the rest of the PLO took in the 1980s and 1990s - or the Irish Republican Army followed in its war with the British.
Western leaders have not yet tried to find out if the Hamas claims of wanting to live in peace with Israel are serious.
But if one of them, perhaps the next US president, wants to break the deadlock in the Middle East's most intractable conflict, then that might have to change.