By Yasmine Saleh and Marwa Awad
CAIRO (Reuters) - Islamist Mohamed Morsy was declared Egypt's first freely elected president on Sunday, sparking joy among his Muslim Brotherhood supporters on the streets who vowed to continue to try to wrest power from armed forces reluctant to cede ultimate control.
But many Egyptians, and anxious Western allies, also urged Morsy to work fast to repair the economy and bitter divisions in society exposed since the overthrow of Hosni Mubarak fractured the police state which had kept the country subdued for decades.
Morsy defeated former general Ahmed Shafik in a run-off last weekend by a convincing 3.5 percentage points, or nearly 900,000 votes, taking 51.7 percent of the total, officials said. It ended a week of disputes over the count that had frayed nerves.
Morsy succeeds Mubarak, who was pushed aside by his fellow officers 16 months ago to appease the Arab Spring revolution.
The military council which has ruled the biggest Arab nation since then, curbed the powers of the presidency by decree last week, meaning the head of state will have to work closely with the army on a planned democratic constitution.
The generals say they want to hand over to civilian rule but are plainly set on defending their privileges and suspicious of the ability of Egypt's fragmented, and long oppressed, political movements to establish a stable constitutional democracy.
The United States, the army's key sponsor and long wary of the rise of political Islam, joined other Western powers in congratulating Morsy and calling on him to form a government of national unity and to respect all Egyptians' civil rights.
Brotherhood officials, speaking as supporters turned Cairo's Tahrir Square into a roaring sea of flags and chants of "Allahu akbar!" (God is greatest), said they would press on with protest vigils to demand that the ruling military council cancel this month's dissolution of the Islamist-led parliament and a decree which gave the generals powers that will restrict the president.
"Morsy is the first truly democratically elected president in Egypt," the Brotherhood's Yasser Ali told Reuters.
"He has the legitimacy and will sit down with the military council and all the political forces to resolve the outstanding issues over parliament and the constitutional decree and the newly imposed emergency law."
"Speak! Have no fear! The military must go!" crowds chanted on Tahrir Square, seat of the revolt, although senior officials in the movement, the veteran adversary of the army for decades, said they wanted to avoid outright confrontation.
There were some isolated scuffles in parts of Cairo between rival groups. Several hundred Shafik supporters in the middle-class suburb of Nasr City chanted "Save Egypt! The Brotherhood will destroy it!", while soldiers tried to keep traffic moving.
Field Marshal Hussein Tantawi, who heads the ruling Supreme Council of the Armed Forces (SCAF), called to congratulate the 60-year-old Morsy on his victory, state television said.
How these two men cooperate will determine Egypt's uncertain path from revolution to democracy and its relations with anxious Arab and Western allies: Tantawi was Mubarak's defense minister for 20 years and has been close to the Pentagon; Morsy, jailed more than once under the old regime, has a doctorate in engineering from the University of Southern California.
PROTESTS GO ON
Another official at the Brotherhood's headquarters, Gihad Haddad, said demonstrations would also continue to press the army: "The peaceful protests will continue in the squares and across Egypt. The struggle for a new Egypt is just beginning."
Those who voted for Shafik as a bulwark against a religious rule that they fear will mean intolerance and alienation from the West were fearful: businessman Maged Abdel Wadud, 45, who had gathered with others at a hotel hoping to greet a victorious Shafik said: "This is a very bad day for Egypt.
"I am so, so upset. I can't imagine this man becoming a president of Egypt. This is the beginning of the end for Egypt."
Some of those backing Shafik accused the military council and Tantawi of "selling out" to the Brotherhood. But a source close to the council itself insisted the election had been entirely fair, in contrast to those under Mubarak.
Describing it as "a true example of democracy to the world" the military council source stressed the pressure was now on Morsy to take responsibility - something many think might backfire on the Brotherhood if Egypt remains in crisis:
"The onus now is on the new president to unite the nation and create a true coalition of political and revolutionary forces to rebuild the country economically and politically," the source said. "The world is now watching the new president to see whether his tenure will reflect all political currents."
Western powers, and Israel, have been concerned about the Islamist turn in Egypt. But Washington and Europe, both big aid donors, have also pressed the military to accept democracy, while urging the Brotherhood to respect all Egyptians' rights - notably those of women and the large Christian minority.
"This is an historic moment for Egypt," said British Foreign Secretary William Hague. "I welcome President Morsy's statement that he intends to form an inclusive government that governs on behalf of all the Egyptian people."
In his congratulations, French President Francois Hollande said: "It is key today that the transition which started in February 2011 continues, so that a democratic and pluralist political system establishes itself in Egypt, guaranteeing civil liberties and political freedom to all citizens."
In Israel, at war with the Brotherhood's Palestinian offshoot Hamas, Prime Minister Benjamin Netanyahu said he "respected" the democratic outcome in Egypt and expected to continue cooperation under the two states' peace treaty.
In Hamas-run Gaza, where Palestinians hope Morsy may end Cairo's cooperation with an Israeli blockade, celebratory gunfire rattled across the crowded coastal territory.
Iran, which is at odds with most Arab states, welcomed what it called an "Islamic awakening" in Egypt.
Reformist Egyptian politician Mohamed ElBaradei, a former U.N. diplomat, tweeted: "It is time for us to all work together as Egyptians in a framework of national consensus."
A senior Western diplomat in Cairo said: "This is a truly historic moment for Egypt - a triumph over the politics of fear and prejudice. Egypt has a civilian, democratically elected president for the first time in its history. The Muslim Brotherhood are far from a perfect organization, but Morsy's election represents a genuine result for the revolution."
He said he did not expect the movement to push its complaints so far as to provoke the military council to react and take from the presidency those powers it still has:
"The Muslim Brotherhood will take what they've got - a prize unimaginable to them 18 months ago," the diplomat said. "An imperfect presidency is way better than none at all.
"It's part of the new and delicate act of political compromise, part of Egypt's new cohabitation."
Half of those who voted in last month's first round of the election backed neither Morsy nor Shafik and many who voted in the run-off voted negatively - either against Morsy's religious agenda or against Shafik as a symbol of military rule.
Hamdeen Sabahy, the secular leftist who finished a close third behind Shafik in the first round, called on Morsy to "swiftly form a national presidential administration and a government that expresses national reconciliation and represents all currents and the diversity of Egyptian society powers".
For Morsy a spokesman said: "This is a testament to the resolve of the Egyptian people to make their voice heard."
Shafik, a former air force commander and Mubarak's last prime minister, offered no immediate reaction. He has said he would offer to serve in a Morsy administration.
Morsy won the first round ballot in May with a little under a quarter of the vote. He has pledged to form an inclusive government to appeal to all the 82 million Egyptians.
"President Morsy will struggle to control the levers of state," Elijah Zarwan, senior policy fellow at the European Council on Foreign Relations, said in Cairo.
"He will likely face foot-dragging and perhaps outright attempts to undermine his initiatives from key institutions. Faced with such resistance, frustration may tempt him to fall into the trap of attempting to throw his new weight around," Zarwan told Reuters. "This would be a mistake.
"His challenge is to lead a bitterly divided, fearful, and angry population toward a peaceful democratic outcome, without becoming a reviled scapegoat for continued military rule."
Morsy has promised a moderate Islamist agenda to steer Egypt into a new democratic era where autocracy will be replaced by transparent government that respects human rights and revives the fortunes of a powerful Arab state long in decline. Morsy is promising an "Egyptian renaissance with an Islamic foundation".
Yet the stocky, bespectacled party official appears something of an accidental president: he was only flung into the race at the last moment by the disqualification on a technicality of Khairat al-Shater, the group's preferred choice.
With a stiff and formal style, Morsy cast himself as a reluctant latecomer to the race, who cited religious fear of judgment day as one of his reasons for running. He struggled to shake off his label as the Brotherhood's "spare tire".
Questions remain over the extent to which Morsy will operate independently of other Brotherhood leaders once in office: his manifesto was drawn up by the group's policymakers. The role Shater might play has been one focus of debate in Egypt.
"I will treat everyone equally and be a servant of the Egyptian people," Morsy said at his campaign headquarters in Cairo shortly after polling ended last Sunday. He gave up his membership of the Brotherhood after being elected.
Turnout was only 51.8 percent of the 50 million-strong electorate, slightly up on the first round but indicative still of a nation unused to having its voice heard without risking punishment and uncertain of the worth of the candidates.
(Additional reporting by Marwa Awad, Tamim Elyan, Tom Perry, Edmund Blair and Patrick Werr; Writing by Alastair Macdonald; Editing by Philippa Fletcher)