Egypt's Muslim Brotherhood declared on Monday that its candidate Mohamed Morsy won the country's first free presidential race, beating Hosni Mubarak's last prime minister and ending six decades of rule by presidents plucked from the military.
But shortly before the final result the generals who have run the country since the overthrow of Mubarak issued new rules that made clear real power remains with the army.
"Mohamed Morsy is the first popularly elected civilian president of Egypt," the official website of Brotherhood's Freedom and Justice Party announced in a brief message.
Morsy in his first comments since the victory announcement promised at a news conference to be president for all Egyptians and said he would not "seek revenge or settle scores."
"Thanks be to God who has guided Egypt's people to the path of freedom and democracy, uniting the Egyptians to a better future," Morsy said.
The Brotherhood said Morsy won 52.5 percent of votes while Ahmed Shafik, an ex-military, secured 47.5 percent, Morsy campaign official Ahmed Abdel Atti told a news conference at the Brotherhood's party headquarters in Cairo. He added that these were initial results.
The figures were based on votes counted at 98 percent of the polling stations, he said. "Down, down with military rule," chanted some of those at the news conference announcing results.
At Shafik's campaign headquarters, Ahmed Sarhan said: "I do not accept this, I will not file wrong numbers." But another campaigner said: "I don't think we will make it." One woman campaigner at Shafik's headquarters was in tears.
A decree from the ruling military council, published as the count got under way on Sunday, spelled out only limited powers for the new head of state and reclaimed for itself the lawmaking prerogatives held by the Islamist-led parliament which the Supreme Council of the Armed Forces (SCAF) dissolved last week.
Liberal and Islamist opponents denounced a "military coup".
The council's "constitutional declaration", issued under powers it took for itself after pushing aside Mubarak to appease street protests 16 months ago, was a blow to democracy, said many who aired their grievances on social media, a favored weapon in the Arab Spring that ended Mubarak's 30-year rule.
"Grave setback for democracy and revolution," tweeted former U.N. diplomat and Nobel peace laureate Mohamed ElBaradei.
"SCAF retains legislative power, strips president of any authority over army and solidifies its control," he said.
"The 'unconstitutional declaration' continues an outright military coup," tweeted Abdel Moneim Abol Fotouh, a moderate Islamist knocked out in the first round of the presidential election last month. "We have a duty to confront it."
A Facebook page whose young activists helped launch the uprising mocked the army's order, noting Egypt would have a head of state with no control over his own armed forces: "It means the president is elected but has no power," one comment read.
The order from Field Marshal Hussein Tantawi, the chairman to the Supreme Council, indicated that the army, which also controls swathes of Egypt's economy, has no intention of handing substantial power now to its old adversary the Brotherhood.
"SCAF will carry legislative responsibilities ... until a new parliament is elected," the council's order said.
It raised a question of how, even if a civilian head of state is sworn in this week, Tantawi can claim to have met his own deadline of July 1 for relinquishing control - a deadline the armed forces' major patron and paymaster the United States had stressed in recent days it was expecting him to respect.
Washington and Egypt's European allies, also major providers of aid to the most populous Arab state, had voiced concern when Tantawi, backed by a judicial ruling from a court appointed under Mubarak, dissolved the parliament elected in January in which the Brotherhood and hardline Islamists had a big majority.
However, the Western powers - and many of Egypt's 82 million people - are also uneasy about the rise of Islamists in Cairo, as in other new democracies of the Arab Spring, notably Tunisia and Libya, and so are unlikely to sanction the generals for now.
The failure of the new parliament to agree a consensus body to draft a constitution - liberals accuse the Islamists of packing the panel with religious zealots - has left Egyptians picking their way from revolution to democracy through a legal maze while the generals control the map and change it at will.
Under the latest order, writing of the new constitution may pass to a body appointed by the SCAF - if a court rules against the contested panel nominated by the now defunct legislature.
Any new constitution would need approval in a referendum, with a new parliamentary election following. By a timetable contained in the decree, it would take another five months or so to complete the planned "transition to democracy".
However, the experience of the past year has left many Egyptians doubting that the military, and what they call the "deep state" stretching across big business, Mubarak-era judges, security officials and the army, will ever hand over control.
"SCAF isn't going to transfer any real power," Marc Lynch, a Middle East expert at George Washington University said on Twitter of the constitutional order. "Back to the beginning."
Turnout, only 46 percent in the first round, appeared to have been no higher for the run-off held over two days.
Many voters were dismayed by an unpalatable choice between a man seen as an heir to Mubarak and the nominee of a religious party committed to reversing liberal social traditions.
Some cast a ballot against both men in protest.
Shafik, 70, said he had heeded the lessons of the revolution and offered security and prosperity for all Egyptians. Morsy, 60, tried to widen his appeal beyond the Brotherhood's committed and disciplined base by pledging to preserve a pluralist democracy and finally end a history of military rule.
The Brotherhood has contested the army's power to dissolve parliament and warned of "dangerous days". But though some have compared events to those in Algeria 20 years, which ended in civil war between the military and Islamists, many doubt that the Brotherhood has an appetite for such violence at present.