Islamist Mohamed Morsy has resigned from his positions within the Muslim Brotherhood after being declared Egypt's first freely elected president.

Mr Morsy, who had promised to quit as chairman of the Freedom and Justice Party (FJP) if victorious, has vowed his leadership will be inclusive, and had courted secular and Christian voters.

Yesterday's election result sparked joy among Muslim Brotherhood supporters who have vowed to continue a struggle to take power from the generals who retain ultimate control.

Mr Morsy defeated former general Ahmed Shafik by a convincing 3.5 percentage points, or nearly 900,000 votes, taking 51.7% of the total and ending a week of disputes over the count.

He succeeds Hosni Mubarak, 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 must work closely with the army.

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 against the ruling military council.

They want the generals to cancel this month's dissolution of the Islamist-led parliament and the decree restricting the president's powers.

"Speak! Have no fear! The military must go!" crowds chanted on Tahrir Square, seat of the Arab Spring revolution that prompted fellow officers to push Mubarak aside to appease the protesters.

Several hundred Shafik supporters in the suburb of Nasr City chanted "Save Egypt! The Brotherhood will destroy it!", while soldiers keep traffic moving.

Field Marshal Hussein Tantawi, head of the ruling Supreme Council of the Armed Forces (SCAF), called to congratulate 60-year-old Mr Morsy on his win.

How these two men cooperate will determine Egypt's uncertain path from revolution to democracy and its relations with anxious Arab and Western allies.

Mr Tantawi was Mubarak's defence minister for 20 years and has been close to the Pentagon. Mr Morsy, jailed more than once under the old regime, has a doctorate in engineering from the University of Southern California.

Brotherhood official Gihad Haddad said demonstrations would 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 Mr Shafik as a bulwark against religious rule – which 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 Mr 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."

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.

A senior Western diplomat in Cairo said: "The Muslim Brotherhood are far from a perfect organisation, but Morsy's election represents a genuine result for the revolution."

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.

"An imperfect presidency is way better than none at all," the diplomat said. "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 Mr Morsy nor Mr Shafik, and many who voted in the run-off voted negatively – either against Mr Morsy's religious agenda or against Mr Shafik as a symbol of military rule.

Liberal member of parliament Amr Hamzawy said: "I salute the elected president and I say to him that he faces a great mission: reassuring the 48%of the citizens who did not give their votes to him."

Mr 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.