A YEAR and a half after the optimism of the Arab spring, the Middle East is in frightening turmoil. Syria is close to sliding into a full-scale civil war whose outcome is unknowable, though its bloodstained president, Bashar Assad, looks likely sooner or later to fall. Libya, mercifully shorn of its crazy tyrant, is being periodically rocked by the still-untamed militias that ousted him; its general election, scheduled for this month, has been pushed back until next. Yemen, having shed its ruling bully of 33 years, has become al-Qaeda's favourite haunt. Tunisia, which had been gliding most smoothly from despotism to democracy, has seen riots by religious extremists (see article). Sudan's vile government and Oman's more amiable one have also both been rattled by protests. And in Saudi Arabia a long-lingering succession crisis is back starkly in the spotlight with the death of its crown prince (see article).

However, the most troubling developments are in Egypt (see article), the Arab world's most populous country. After 18 months of messy progress towards democracy, the army seems determined to reverse the march to freedom, or at least to put a heavy brake on it. If Egypt goes wrong, then democracy's progress elsewhere in the Arab world will be far slower.

Egypt is not, however, doomed to return to dictatorship. Turkey, where the army has reached an accommodation with moderate Islamists, points to a peaceful way out. And the West can help by making it clear that democratically elected politicians, even Islamist ones, rank above generals.

Who's actually in charge?

As The Economist went to press, the power struggle between the army and the Islamists was intensifying. News that Hosni Mubarak, ousted last year after 30 years as despot, was near to death after a stroke in prison may be irrelevant to the outcome of the current power struggle. But it is a ghostly reminder of how politically moribund Egypt used to be.

On the more hopeful side, it looks as if Muhammad Morsi, a member of the Muslim Brotherhood, will still probably be declared the winner of the run-off for president, beating Ahmed Shafiq, a general and Mr Mubarak's last prime minister; if so, President Morsi should take office by July 1st. This in itself would be a momentous event, marking the first time in Egypt that a reasonably free presidential election had been held, producing a head of state legitimised by the popular will, albeit in a polarised society. It would also be the first time in the Arab world that an Islamist president had come to power by democratic means. Mr Morsi would—it is still assumed—be empowered to appoint a government and take his place as Egypt's democratically chosen leader on the global stage.

But too little of this is certain. At its worst, the army could declare that Mr Shafiq has somehow won. Even if Mr Morsi's victory is accepted, it is not clear what powers he will have. The Supreme Council of the Armed Forces (SCAF), a cabal of a score or so of generals who became the caretaker rulers after Mr Mubarak's fall, has never been keen to let Egypt become a fully fledged democracy. But the SCAF now seems to have gone back on its earlier promise to withdraw to its barracks. A week ago the generals told the pliable Mubarak-era judges on the constitutional court to dissolve the new parliament, which had produced a strong Islamist majority, on ridiculously technical grounds that could have been aired months ago. Now the SCAF claims the power to lay down the laws that the parliament was expected to pass and even to draw up the budget. It will also have the right to choose and direct a constituent assembly or a constitution-drafting body to produce a document spelling out the president's powers and, presumably, new rules for fresh elections to parliament.

These are threatening moves, but so far at least this does not seem to be a counter-revolution. Rather than a hard coup intended to snuff out the country's evolving democracy, it is an attempt to slow and control it. The army's priority is keeping its “special role”, its economic privileges and some of the ministries of power, such as defence and internal security, much as Turkey's generals did in the 1990s, when they blocked a democratically elected Islamist government and continued forcibly to parade themselves as guardians of a secular order.

If the Turkish analogy is pursued, the outcome may yet hold out hope. Turkey has suffered more than its share of coups and political violence. But those dangers have receded as the Islamists have proved moderate and popular, winning three fair elections in a row and whittling away the generals' power. Although the “deep state”, sinister and pervasive in Turkey as it plainly still is in Egypt, lingers in the apparatus of security and repression, Turkey's Islamists have won the moral authority to send the soldiers back to barracks, and have exercised it. If Egypt follows this path, nothing the generals have done this week will stop the march to democracy for long.

Wield the stick, Mr Obama

There are two canards that politicians in the West use as an excuse for ignoring the Arab spring. The first is that there is little to choose between the generals and the Islamists. This is just Mubarakism revisited. This newspaper did not want the Islamists to trounce the secular reformers, but they did. The best way to tame the Islamists, as Turkey's experience shows, is to deny them the moral high ground to which repression elevates them, and condemn them instead to the responsibilities and compromises of day-to-day government.

The second argument is that Egypt is too complex for the West to influence. The situation is certainly messy; but messages from the outside can be clear and strong. Frequent insistence that the army sticks to its democratic promises could make a difference. The generals thrive on American aid and are plainly nervous about seizing untrammelled power. By pressing them to negotiate with Mr Morsi over a constitution to provide for a new parliament, the United States and Europe could tip the balance in democracy's favour.

In Egypt's confusion, one thing stands out: Egyptians, and Arabs elsewhere, want to run their own affairs. Kings or generals may slow progress to that end, but they cannot stop it.

Correction: Turkey's generals blocked a democratically elected government in the 1990s, not the 1980s as originally stated above. This was corrected on June 22nd 2012.