Well, so much for exit polls and so much for democratisation. The United States under George W Bush has valiantly pursued (minus a few blind spots) the cause of democracy in the Middle East, in the fond belief that free elections would produce pro-American and pro-Israeli governments in Arab countries. This was always just a fantasy, but it had never been so brutally exposed as it was this week.

Wednesday’s election in the Palestinian territories was a landslide victory for the militant Islamic party, Hamas. Official provisional figures give Hamas 76 seats, against 43 for Fatah and 13 for smaller parties and independents. In the territory-wide seats, which reflect overall support, Hamas won 30 to Fatah’s 27, but divisions within Fatah gave Hamas 46 of the 66 constituency seats.

At one level, this is inspirational stuff. Two armed groups with a bloody history have submitted to the verdict of a fair election. Fatah prime minister Ahmed Qurei has resigned, and Fatah leaders have promised to serve as a democratic opposition and allow Hamas to form a government. This sort of thing has been all too rare in the Arab world.

But a commitment to democracy means accepting the risk that the wrong side might win. The already-fraught “peace process” will now be put to its severest test, since Israel can hardly be blamed for ruling out a partnership with a armed group committed to its destruction.

It remains true, as I said last month, that for a lasting peace to happen Israel and Hamas are one day going to have to sit down and talk to each other. But it had been expected that that was something the parties would be able to ease into gradually. Now Hamas, and therefore Israel as well, has been thrown in at the deep end.

No doubt victory will change Hamas. In the words of Daoud Kuttab, a Palestinian analyst quoted in The New York Times, “Hamas will be in power and find out what it will be like to live in the real world. Hamas will have to face reality, and part of reality means dealing with Israel.”

But how long it might take for that reality to dawn, and what the region might have to go through in the meantime, makes for an unpleasant prospect.