By Yasmine Saleh and Shaimaa Fayed
CAIRO (Reuters) - Islamist Mohamed Morsy of the Muslim Brotherhood was declared Egypt's first democratic president on Sunday by the state election committee, which said he had defeated former general Ahmed Shafik with 51.7 percent of last weekend's run-off vote.
He succeeds Hosni Mubarak, who was overthrown 16 months ago after a popular uprising. The military council which has ruled the biggest Arab nation since then has this month curbed the powers of the presidency, meaning the head of state will have to work closely with the army on a planned democratic constitution.
Thousands of Brotherhood supporters burst into cheers on Cairo's Tahrir Square, waving national flags, setting off fireworks and chanting "Allahu Akbar!" or God is Great, greeting a dramatic victory, tempered by the army's continuing role.
"Say! Don't fear! The military must go!" crowds chanted.
For Morsy, a U.S.-educated engineer who spent time in jail under Mubarak, 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, 60, 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 the many Egyptians, including a large Christian minority, who are anxious over religious rule.
The military council will retain control of the biggest army in the Middle East, whose closest ally is the United States. Morsy has said he will respect international treaties, notably that signed with Israel in 1979, on which much U.S. aid depends.
"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 will not enjoy the extent of modern, pharaonic powers exercised by Mubarak: those have been curtailed by a military establishment which will decide just how much he will be able to do in government. The Brotherhood had said it would press on with protests against the army's latest rulings.
Still, his victory in the country's first free presidential election breaks a tradition of domination by men from the armed forces, which have provided every Egyptian leader since the overthrow of the monarchy 60 years ago, and installs in office a group that drew on 84 years of disciplined grassroots activism to catapult Morsy into the presidency.
He has promised a moderate, modern 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, who has a doctorate from the University of Southern California, 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, a week before his victory was confirmed by the Mubarak-era judicial body overseeing the vote.
But many Egyptians, not least the Christian minority, remain suspicious of Morsy and even more so of the group he represents. Anti-Brotherhood sentiment, fuelled by both a hostile media and some of the group's policies, has soared in recent weeks.
(Additional reporting by Marwa Awad, Tamim Elyan, Tom Perry, Edmund Blair and Patrick Werr; Writing by Alastair Macdonald; Editing by Edmund Blair and Philippa Fletcher)