A few months ago U.S. President Barack Obama declared that al-Qaida was "on the path to defeat." Its surviving members, he said, were more concerned for their own safety than with plotting attacks on the West. Terrorist attacks of the future, he asserted, would resemble those of the 1990s, local rather than transnational and focused on "soft targets."
His overall message was that it was time to start winding down former president George W. Bush's war against global terrorism.
Obama might argue the assault on the Westgate shopping mall in Nairobi by al-Qaida's Somali affiliate, the Shabab, was exactly the kind of thing he was talking about: lethal, shocking, but a long way from the United States.
Still, the inconvenient truth is, in the past 18 months, despite the relentless pummeling it has received and the defeats it has suffered, al-Qaida and its jihadist allies have staged an extraordinary comeback. The terrorist network now holds sway over more territory and is recruiting more fighters than at any time in its 25-year history.
It all looked different two years ago. Even before the killing of Osama bin Laden in 2011, al-Qaida's central leadership, holed up near the Afghan border in Pakistan's North Waziristan, was on the ropes, hollowed out by drone attacks and able to communicate with the rest of its network only with difficulty and at great risk.
Al-Qaida in the Arabian Peninsula, its most capable franchise as far as mounting attacks on the West is concerned, was being hit hard by drone strikes and harried by Yemeni troops. The Shabab was under similar pressure in Somalia, as Western-backed African Union forces chased them out of the main cities.
Above all, the Arab spring had derailed al-Qaida's central claim corrupt regimes supported by the West could be overthrown only through violence.
All those gains are now in question. The Shabab is recruiting more foreign fighters than ever, some of whom appear to have been involved in the attack on the Westgate. AQAP was responsible for the early-August panic that led to the closure of 19 American embassies across the region and a global travel alert. Meanwhile al-Qaida's core, anticipating the withdrawal of western troops from Afghanistan after 2014, already is moving back into the country's wild east.
Above all, the souring of the Arab spring has given al-Qaida and its allies an unprecedented opening. The coup against a supposedly moderate, elected Islamist government in Egypt has helped restore al-Qaida's ideological power. Weapons have flooded out of Libya and across the region, and the civil war in Syria has revived one of the network's most violent and unruly offshoots, al-Qaida in Iraq, now grandly renamed the Islamic State of Iraq and al-Sham.
The struggle to depose the Assad regime has acted as a magnet for thousands of would-be jihadists from across the Muslim world and from Muslim communities in Europe and North America. The once largely moderate and secular Syrian Free Army has been progressively displaced by better-organized, better-funded jihadist groups that have direct links with al-Qaida.
Western intelligence estimates reckon such groups now represent as much as 80 per cent of the effective rebel fighting force. Even if they fail to advance much from the territory they now hold, in the north and east of the country, they might end up controlling a vast area that borders an ever-more-fragile-looking Iraq, where al-Qaida is currently murdering as many as 1,000 civilians a month. That is a terrifying prospect.
How much should Western complacency be blamed for this stunning revival? Quite a bit. Obama was too eager to cut and run from Iraq, and he is at risk of repeating the mistake in Afghanistan. America has been over-reliant on drone strikes to "decapitate" al-Qaida groups. Former U.S. defence secretary Leon Panetta even foolishly talked of defeating the network by killing as few as 10 to 20 leaders in Pakistan, Somalia and Yemen. The general perception of America's waning appetite for engagement in the Middle East, underlined by Obama's reluctance to support the moderate Syrian opposition in any useful way, has been damaging as well.
A second question is how much of a threat a resurgent al-Qaida now poses to the West. The recently popular notion that, give or take the odd homegrown "lone wolf," today's violent jihadists really are interested only in fighting local battles now looks mistaken.
Some of the foreign fighters in Syria will be killed. Others will be happy to return to a quieter life in Europe or America. A significant proportion, however, will take their training, experience and contacts home, keen to use all three when the call comes, as it surely will. There is little doubt westerners working or living in regions where jihadism is strong will be doing so at greater risk than ever.
The final question is whether anything can be done to reverse the tide again. The answer is surely yes.
When Bush declared his "war on terror," his aim was the removal of regimes that sponsored terrorism. Today the emphasis should be on supporting weak, sometimes unsavory governments in Iraq, Libya, Mali, Niger, Somalia, Yemen and elsewhere that are trying to fight al-Qaida. Even Kenya and Nigeria could do with more help. That does not mean a heavy-boot print on the ground, but rather assistance in intelligence, logistics and even special forces and air support.
Most of all, it means more help to train local security forces, to modernize administrations and to stabilize often-frail economies.
The most dismaying aspect of al-Qaida's revival is the extent to which its pernicious ideology, now aided by the failures of the Arab spring, continues to spread through madrassas, mosques and jihadist Web sites and TV channels. Money still flows from rich Gulf Arabs, supposedly the West's friends, to finance these activities and worse.
More pressure should be brought to bear on their governments to stop this. For all the West's supposedly huge soft power, it has been feeble in its efforts to win over moderate Muslims in the most important battle of all, that of ideas.