Caught by Surprise. Again.

In the late 1970s, American officials were aware that the Shah of Iran was losing domestic support. They analyzed alternate scenarios and studied various opposition groups. They thought they were being very bold in their outreach, talking to Marxists, dissidents and other radicals. But they paid little attention to the turban-clad clerics preaching dissent via mosque, audiotape and pamphlet. How many people could possibly support mullahs promising a return to theocracy in the late 20th century?

Thirty years later, we're still surprised, and still asking the same questions. How could the Palestinians vote for a party that wants to create an Islamic state? We might even ask the question in Iraq, where elections have yielded consistently for hard-line Islamic parties (and hard-line ethnic parties, in the case of the Kurds).

Let's stop for a moment and understand how this happened, so that at least we can stop being surprised. The story of the rise of Hamas mirrors the rise of almost all such Islamic political parties in the Middle East.

For decades, the dictators who ruled (and rule) the Middle East destroyed all political opposition groups. They were particularly aggressive in co-opting or exterminating liberal, secular, forward-looking groups because those were seen as most threatening. They were often less harsh toward Muslim groups, partly because the Islamists were seen as less political. And, of course, you cannot ban the mosque in an Islamic country.

Rulers like Anwar Sadat and Jordan's King Hussein often used Islamic groups to discredit the secular opposition. Decades of repression, incompetence and stagnation ensured that citizens got increasingly unhappy with their regimes. And the only organized, untainted alternative was the Islamic movement.

Consider Hamas. It was founded as a sister group of Egypt's Muslim Brotherhood. Initially it was a "quietist" group, accepting Israel's occupation of the West Bank as a fact and simply working to improve the conditions of Palestinians within it. Both Israel and Jordan tacitly supported the group during that period, because they saw it as a way of dividing the Palestinians. They also probably believed it could never come to power. But they worked tirelessly to destroy the PLO and its successor, Fatah, a secular, Soviet-styled revolutionary outfit. (Remember that in the 1970s, even the United States thought that conservative Islamic groups were allies against left-wing revolutionary ones, which is why we funded the mujahedin in Afghanistan.)

But the man who truly opened the space for Hamas was Yasir Arafat. Arafat created one of the most ill-disciplined, corrupt and ineffective organizations ever to be taken seriously on the world stage. Despite the pull of loyalty in tough conditions, Palestinians were losing faith in Fatah through the 1990s. Hamas, meanwhile, became more political, radical and organized. It provided health, education and other social-welfare services. And it stood up for its people.

For someone in Gaza, here is the contrast. Arafat was corrupt, and could not deliver on a Palestinian state. Hamas is honest, effective and holds firm. As Palestinians watched Arafat dither and Abbas fail, they lost any faith that Fatah has a path--by force or by negotiations--to get them a state. And meanwhile, their daily life was getting worse and worse while their leaders drove around in Mercedes cars.

Much is now being written on how Hamas will have to moderate itself to rule. But the next few months, if not years, will be a very rocky ride. If we are to learn something from this experience, it should surely be that now is the time to start building and shoring up the secular groups, the middle-class organizations, the liberal-minded civil society of the Middle East.

Today these groups barely exist. They have struggled under laws designed to prevent them from forming, with no free press to voice their views, no business supporters to give them money and muscle. "Right now we do not have a level playing field," says Bassem Adwadallah, a young Jordanian reformer. "For 30 years Islamic groups have been the only ones allowed in the political space. We liberals are just starting. We need to stop bickering, be better organized, present a persuasive program. But we also need some help."

President Bush has said that democracy promotion is a "growth industry." If it is, then funding such groups and helping them deliver for their people is surely the best way to invest. Without that you'll have elections in the Middle East but no real democracy.