Story highlights Yemen's future is far from predictable after Saleh's departure, an analyst says

Armed units from the Saleh family and the al-Ahmar family remain at odds

The tens of thousands of anti-Saleh demonstrators are likely to play a role

A combination of factors probably led Saleh to finally step down

After months of bloodshed, intrigue and revenge that made Yemen seem like an Arabian version of Hamlet, President Ali Abdullah Saleh has finally transferred his powers to his vice president, and elections are to be held in three months.

At the ceremony in Riyadh, Saudi Arabia, to seal the transition deal worked out by the Gulf Cooperation Council, Saleh seemed relaxed and even chuckled as he signed several copies of the agreement, the result of intense diplomatic shuttling by U.N. envoy Jamal bin Omar and growing pressure from the international community.

But Saleh also took a parting shot at his opponents, saying they had destroyed in months everything that had been built over years.

April Longley Alley, Yemen analyst at the International Crisis Group, says the Riyadh deal offers an "opportunity to move past the current political impasse and to deal with critical issues like deteriorating economic and humanitarian conditions as well as the very difficult task of institutional reform."

Even so, Longley Alley and other analysts expect the epilogue to be anything but predictable. There are plenty of competing elements left behind: the thousands of mainly young demonstrators who took to the streets of Sanaa and other cities in January to demand democratic change, the tribal alliance that took up arms against Saleh, secessionists in the south and a Shiite rebellion in the north, well-organized Islamist groups and a budding al Qaeda franchise.

JUST WATCHED Yemeni women burn veils in protest Replay More Videos ... MUST WATCH Yemeni women burn veils in protest 02:29

JUST WATCHED Yemen's youth continue calls for change Replay More Videos ... MUST WATCH Yemen's youth continue calls for change 02:39

Perhaps the most powerful figure in Yemen now is Brig. Gen. Ali Mohsen al-Ahmar, commander of the 1st Armored Division. He defected in March and took a chunk of the army with him. His units now control northern districts of the capital and are facing off against powerful remnants of the Saleh clan. The president's son, Ahmed Ali Abdullah Saleh, long groomed to be his successor, and his nephew, Yahya Muhammad Saleh, command the most effective units.

Longley Alley says the Gulf Cooperation Council accord "does not deal effectively with lingering tensions between Saleh's family on one hand and Ali Mohsen al-Ahmar and the powerful al-Ahmar family on the other. Each of these power centers is heavily armed and still poised to fight."

As if to remind the diplomats of the scale of the task ahead, pro- and anti-Saleh factions clashed in Sanaa hours before the ceremony. The challenge of "securing a cease-fire, removing armed tribesmen from urban centers, returning the military to the barracks and engaging in military-security reform will be serious stumbling blocks post-signing," according to Longley Alley.

Al-Ahmar makes some Western officials nervous because of his links with radical Sunni Islamists. Yemeni observers say the Muslim Brotherhood has long been influential within al-Ahmar's military command, and he is known for his antipathy toward Yemen's Shiites. A U.S. diplomatic cable from 2005 said that "Ali Mohsen's questionable dealings with terrorists and extremists would make his accession unwelcome to the U.S. and others in the international community."

Others in this powerful clan include Hamid al-Ahmar, a leader of the Islamist party Islah and a prominent businessman who has long been an opponent of the president. His brother Sadiq also has armed supporters in and around Sanaa.

For generations, the Yemeni state has done little without the al-Ahmars' blessing. Sheikh Abdullah Bin Hussein al-Ahmar, who died in 2007, was one of the few Yemenis to command widespread respect -- a man often described as the father of modern Yemen. He was an opposition leader but also speaker of the Parliament, and Saleh was careful not to cross him. Today, there seems no one of similar stature.

The tens of thousands of demonstrators who have braved gunfire, tear gas and pro-government gangs in Sanaa, Taiz and elsewhere are unlikely to be satisfied by Saleh's departure. They fear being marginalized by the transfer of power from one clique to another as part of some "tribal bargain" and oppose Saleh's immunity from prosecution, which is part of the Riyadh deal.

But Longley Alley says they have a role to play. "The independent youth in Yemen have at times been marginalized by the armed conflict. While these young people do not have guns or butter, they are beginning to organize and to recognize their potential influence."

Others who may play a significant role include the cleric Abdul Majid al-Zindani, who heads the Salafist (very conservative) wing of the Islah party. He is feared by liberal Yemenis.

But ultimately, as one U.S. diplomatic cable sent from Sanaa in 2005 put it, "True power still derives from the military and the tribes."

As for the 69-year old Saleh himself, a combination of factors probably led him to choose this moment to sign away his powers. He still needs medical treatment for the burns sustained in an attack on the Presidential Palace in June -- injuries that left him in a Saudi hospital for three months. U.N. Secretary-General Ban Ki-moon said Saleh told him he would be traveling to New York for treatment soon.

Another possible reason is that Saleh has seen the violent end of Moammar Gadhafi and growing pressure on Bashar al-Assad in Syria. He also has been subject to intense diplomatic pressure by Saudi Arabia and the United Nations finally to ratify the Gulf Cooperation Council deal. The European Union had begun considering sanctions. And military units loyal to the president have lost ground in recent weeks.

But what are his plans now? No one has the definitive answer. The intrigue is reminiscent of the Congress of Vienna in 1815 that drew the post-Napoleonic map of Europe. When the Russian envoy died suddenly, Austria's Prince Metternich is reputed to have said: "I wonder what his motive was."

Whatever power structure emerges, Yemen's next leaders will face daunting tasks as they inherit a state where oil revenues have declined and the economy is in ruins, where poverty is endemic and a young and rapidly growing population faces a chronic shortage of water. Not to mention the percolating rebellions in the south and north, and a well-entrenched affiliate of al Qaeda.

To recall a line from Hamlet that might well apply to Yemen today:

"When sorrows come, they come not single spies,

"But in battalions."