Team O at its worst.

An unprecedented attack yesterday on the presidential palace in San'a, Yemen, injured President Ali Abdullah Salah and his top allies -- just as Obama's chief anti-terrorism adviser, John Brennan, arrived in the region for a belated Yemen look-see. As the Islamist terrorists' wettest Yemeni dream -- civil war -- gets in high gear, America is fast turning into a helpless bystander.

And this is the nation where our intelligence agencies have long believed the next terrorist attacking America is most likely to come from. All the ills that plague the Middle East -- repression, poverty, hopelessness, tribalism, overzealous Islam -- loom even larger there.

United against their prez: A mass funeral for anti-regime fighters in San'a yesterday.

Getty

United against their prez: A mass funeral for anti-regime fighters in San'a yesterday.

Alas, looming extra-larger in our Yemen policy are all the ills of President Obama's approach to Mideast turmoil -- hesitance, lack of direction, failure to lead from the front, wild overoptimism about what diplomacy's likely to achieve and misreading of the political terrain.

To be fair, Yemen ain't easy. After 32 years in power, even Saleh seems to have lost his read on his country's political maze.

Saleh is now on his way out -- taking with him whatever strategy we had for keeping Al Qaeda in the Arabian Peninsula at bay. The coming chaos perfectly suits AQAP, which has reportedly already captured the coastal city of Zinjibar and is ready to emerge as Yemen's ultimate kingmaker, as al Qaeda proper once did in Afghanistan.

The wider Mideast unrest reached Yemen four months ago -- launched, as elsewhere, by hopelessly frustrated young people looking to poke the existing order. Saleh handled the initially peaceful uprising the only way he knew: He shot at the troublemakers while trying to play all sides against the middle.

This time, it didn't work. One of his own generals, Ali Mohsen, defected, adding a military dimension to the unrest. Then the country's powerful Ahmar clan, which has pulled Yemen's strings for generations, turned against him.

(Saleh's aides blamed the Ahmars for yesterday's brazen missile attack, targeting a mosque inside the presidential compound -- but Mohsen's troops are equally suspect.)

Neighbors and Western diplomats begun to recognize the end. Emissaries of the Saudi-led Gulf Cooperation Council hashed out an agreement (although a diplomat familiar with the talks told me that the deal was actually shaped by the US ambassador in San'a, Gerald Feierstein).

Under the GCC deal, Saleh agreed to cede power in exchange for immunity from future prosecution. At least he led everyone to believe he'd agreed.

For Saleh, the deal was all about the loopholes. His proposed resignation, for example, hinged on parliamentary ratification -- but Parliament is dominated by Saleh allies who, if so commanded, were ready to "reject" his resignation.

The backroom diplomatic maneuvering failed, in other words, because the mediators believed the president's hold on power was doomed -- but he didn't. So he kept leading everyone on, and the deal collapsed three times.

Now the current crisis is most likely to prove him wrong and usher even greater chaos. Even if he survives, he'd owe his seat to some of Yemen's darkest forces.

As elsewhere in the Arab world, our Yemen anti-terror policy has for years depended solely on a slick operator who promised to fight AQAP. Saleh used our anti-terror money to fight his political enemies and bribe tribal leaders into alliances; in return, he let our drones operate against AQAP targets (as long as we didn't advertise his compliance).

When the unrest started, the Obama team at first failed to recognize that Saleh's hold on power was unraveling, and then failed to spell out a vision for Yemen's future.

Worse, the United States failed to identify, support and finance potential local allies to replace Saleh in power: Several Western-educated opposition leaders could have gained the support of tribal chieftains, a diplomat familiar with the country's factions told me -- if the US had convinced everyone of its complete backing of those leaders. We didn't.

Yemen is the poorest Arab country. It can no longer guarantee water for its citizens, let alone other life necessities; its population is uneducated, fractured and militaristic. But a strategic location on an important naval artery and proximity to our most important regional oil supplier, Saudi Arabia, makes it much more than yet another Arab backwater.

Regrettably, we have very few tools left to compete with AQAP. All Brennan can do now is huddle with the Saudis, take a deep breath and pray for the best.