The Egyptian chapter of the "Arab Spring" ended not as it was scripted by the revolutionaries of Tahrir Square.
They deposed a military dictator, secured the first free presidential race in their history, and then may have lost it to a die-hard Islamist president. Not only this. The generals who had stood behind Hosni Mubarak remain firmly entrenched.
The Muslim Brotherhood claimed its candidate Mohamed Morsy, 60, won the election against military rival Ahmed Shafik, 60, but a sweeping legal maneuver by Cairo's military rulers made clear the generals planned to keep control for now -- even if Shafik's refusal to concede defeat turns out to be justified.
"This is more an episode in an ongoing power struggle than a real election," Anthony Cordesman, a veteran former U.S. intelligence official and now the Washington-based Center for Strategic and International Studies, told Reuters.
"It is unclear who will rule, who the real leaders will be, and who - if anyone - represents the people. What is clear is that Egypt is no closer to stability and a predictable path to the future than before."
In reality, the new president will be subordinate for some time at least to the 20-man military council which last year pushed fellow officer Mubarak aside to appease street protests.
In the latest twist on Egypt's far from complete path to democracy, the generals issued a decree on Sunday as voting ended which clipped the wings of the president by setting strict limits on his powers and reclaiming the lawmaking prerogatives held by the assembly it dissolved last week.
"This is their insurance policy against a Muslim Brotherhood victory. It shows the extent to which they (the generals) are willing to go to maintain their interest and their stranglehold on power," said Salman Shaikh of the Brookings Doha Center.
The power struggle, analysts say, will almost certainly escalate between the two Leviathan powers after the army, which controls swathes of Egypt's economy, indicated that it had no intention of handing power to its old enemy the Brotherhood.
"This is the culmination of decades of rivalry between the army and Islamists," Shaikh said. "This could really explode."
"If we see any more aggressive approach then we will be talking about something similar to Algeria," he said, referring to Algeria in 1992 when the army dissolved parliament after Islamists won a vote and 20 years of conflict followed.
Adding to the legal quagmire, a ruling in a case challenging the legality of the Brotherhood, which under Mubarak was banned, could be issued on Tuesday.
The rulings further consolidated powers in the army's hands, after the justice ministry gave the generals and intelligence service extraordinary powers to arrest, detain and prosecute civilians without judicial warrants.
"What happens shows that it is a very deep state not willing to let go. It shows a dark side for this regime," Shaikh said.
Despite its victory declaration based on initial counts which gave it 52 percent compared to 48 percent, the Brotherhood is not out of the woods yet.
There are a number of scenarios under which the Brotherhood victory could be sabotaged. Although monitors have broadly given guarded approval to the vote there may yet be enough reports of irregularities should a determined state wish to use the judiciary to contest the result.
The onus, diplomats said, would be on the United States - major patron and paymaster of the army - to pressure Field Marshal Hussein Tantawi to meet his own deadline of July 1 for relinquishing control and allow a civilian president to rule.
The two candidates faced off in a second run-off which polarized the nation and left a section of society, which ousted Mubarak in popular protests, out of the game with neither of the candidates appealing to their liberal or reformist aspirations.
Many voters were dismayed by the choice between a man seen as an heir to Mubarak and the nominee of a religious party who they feared would reverse liberal social traditions.
The Brotherhood has contested the army's power to dissolve parliament and warned of "dangerous days" ahead. But their stamina, diplomats and observers said, has been sapped by 16 months of a messy and often bloody transition.
Diplomats said the group, outlawed under Mubarak, may well avoid confrontation on the streets for fear of offering its opponents in the deep state a pretext to crack down on them.
"What the counter revolutionary forces would like is for the Muslim Brotherhood to throw their forces onto the street then there would be a real pogrom. That is why I don't think it will happen," said one senior Western diplomat.
"I think the Brotherhood...would keep their people under control," the diplomat said.
Tensions flared with the military when the Islamist group reneged on their pledge not to run for the presidency, a U-turn that came hard on heels of a bigger victory in parliament than it had said it would seek.
The diplomat said it was "a shock to everybody", notably the army when the Brotherhood named Khairat al-Shater as the group's first choice only to have him disqualified, forcing it to name Morsy instead.
Adding to its missteps, legislation proposed by some of its MPs to impose Islamic strictures turned the tide of public support against them. Some Egyptians also looked nervously at Islamist-fuelled militancy and violence in Tunisia.
For many Egyptians their revolution, which followed Tunisia's, now seems victim of a coup by generals who changed the chief executive, Mubarak, but have not touched the deep state that kept him and his predecessors in power for six decades.
Since the army toppled the colonial-era monarchy in 1952, it has built massive wealth and commercial interests across industries, followed by a close U.S. alliance that came with the signing in 1979 of a peace treaty with Israel. With this web of interests and alliances, it is unlikely it will cede its power.
The worry for the military is that the Brotherhood could eventually challenge their position, just as Turkey's AK Party with its Islamist has reined in the generals there. The military also worries that Islamists with their fiery anti-Israel rhetoric will weaken the deal with Israel.
Regionally, the rise to power of the Brotherhood in the Arab world's most populous nation would unnerve Gulf Arab monarchies which have managed to avoid being swept away by an Arab Spring that has also toppled leaders in Tunis, Libya and Yemen.
Israel frets that the Brotherhood will embolden its offshoot, the Islamist Palestinian Hamas movement which is at war with Israel.
Despite regional and domestic misgivings the election was unprecedented for a nation which has never given ordinary Egyptians the chance to freely pick their leaders in a history that stretches back thousands of years.
But a toothless president, a dissolved parliament and an ascendant military in a country without a constitution is not what most Egyptians had in mind when they poured onto the streets to drive out Mubarak at the start of 2011.
"It is not the end of the story, but somebody flipped us back to page one," the diplomat said.
"Egypt is increasingly hard-wired for greater chaos and instability. It is an extremely tense and volatile environment. Nobody knows what will happen," Shaikh said.
(editing by Ralph Boulton)
(Additional reporting by Edmund Blair)