CAIRO (AP) -- Islamist Mohammed Morsi was declared the winner Sunday in Egypt's first free presidential election in history, closing the tumultuous first phase of a democratic transition and opening a new struggle with the still-dominant military rulers who recently stripped the presidency of most of its powers.
In Tahrir Square, the birthplace of the uprising that ousted autocratic President Hosni Mubarak, joyous Morsi supporters wept and kneeled on the ground in prayer as soon as they heard the outcome announced live television. They danced, set off fireworks and released doves in the air with Morsi's picture attached in celebrations not seen in the square since Mubarak was forced out on Feb. 11, 2011.
Many are looking now to see whether Morsi will try to take on the military and wrestle back the powers they took from his office just one week ago. Thousands vowed to remain in Tahrir to demand that the ruling generals reverse their decision.
"I pledge to be a president who serves his people and works for them," Morsi said on his official web page. "I will not betray God in defending your rights and the rights of this nation." He was scheduled to address the nation Sunday night in his first speech after being declared president.
The White House congratulated Morsi and urged him to advance national unity as he forms a new government. White House press secretary Jay Carney said Morsi's victory is a milestone in Egypt's transition to democracy after decades of authoritarian rule under Mubarak. The Obama administration had expressed no public preference in the presidential race.
Left on the sidelines of the political drama are the liberal and secular youth groups that drove the uprising against Mubarak, left to wonder whether Egypt has taken a step towards becoming an Islamist state. Some grudgingly supported Morsi in the face of Ahmed Shafiq, who was Mubarak's last prime minister, while others boycotted the vote.
Morsi will now have to reassure them that he represents the whole country, not just Islamists, and will face enormous challenges after security and the economy badly deteriorated in the transition period.
Pro-democracy leader Mohammed ElBaradei urged unity after the results were announced.
"It is time we work all as Egyptians as part of a national consensus to build Egypt that is based on freedom and social justice," he wrote on his Twitter account.
The elections left the nation deeply polarized with one side backing Shafiq, who promised to provide stability and prevent Egypt from becoming a theocracy. Because of his military career, many saw him as the military's preferred candidate.
In the other camp are those eager for democratic change and backers of Morsi's Muslim Brotherhood who were persecuted, jailed and banned under Mubarak but now find themselves one of the two most powerful groups in Egypt.
The other power center is the ruling military council that took power after the uprising and is headed by Mubarak's defense minister of 20 years.
Just one week ago, at the moment polls were closing in the presidential runoff, the Supreme Council of the Armed Forces (SCAF) issued constitutional amendments that stripped the president's office of most of its major powers. The ruling generals made themselves the final arbiters over the most pressing issues still complicating the transition- such as writing the constitution, legislating, passing the state budget- and granted military police broad powers to detain civilians.
"I am happy the Brotherhood won because now the revolution will continue on the street against both of them, the Brotherhood and the SCAF," said Lobna Darwish, an activist who has boycotted the elections.
Also, a few days before that constitutional declaration, a court dissolved the freely elected parliament, which is dominated by the Muslim Brotherhood, leaving the military now in charge of legislating.
Brotherhood members and experts said the results were used a bargaining chip between the generals and the Brotherhood over the parameters of what appears to be a new power-sharing agreement. The country's new constitution is not written and the authorities of the president are not clear.
This is the first time modern Egypt will be headed by an Islamist and by a freely elected civilian. The country's last four presidents over the past six decades have all came from the ranks of the military.
"Congratulations because this means the end of the Mubarak state," said Shady el-Ghazali Harb, a prominent activist who was among the leaders of the protests in January and February last year.
The results of the elections were delayed for four days amid accusations of manipulation and foul play by both sides, raising political tensions in Egypt to a fever pitch.
The delay plunged the country into nerve-wrecking anticipation and pushed tensions to a fever pitch. Parallel mass rallies by Shafiq and Morsi supporters were held in different parts of Cairo and cut-throat media attacks by supporters of both swarmed TV shows. In the hours before the announcement of the winner, the fear of new violence was palpable.
Heavy security was deployed around the country, especially outside state institutions, in anticipation of possible violence. Workers were sent home early from jobs, jewelry stores closed for fear of looting and many were stocking up on food and forming long lines at cash machines in case new troubles began.
Morsi, the 60-year old U.S.-trained engineer, narrowly defeated Shafiq with 51.7 percent of the vote versus 48.3, by a margin of only 800,000 votes, the election commission said. Turnout was 51 percent.
Farouk Sultan, the head of the commission, described the elections as "an important phase in the end of building our nascent democratic experience."
Sultan went to pains to explain the more than 400 complaints presented by the two candidates challenging counting procedures and alleging attempts of rigging. It appeared to be an attempt to discredit claims that the election commission was biased in favor of Shafiq, the candidate perceived as backed by the military rulers.
The country is deeply divided between supporters of the Brotherhood, liberals and leftists who also decided to back them as a way to stand up to the military, and other secular forces that fear the domination of the Brotherhood, and grew critical of it in the past year. The small margin of victory for Morsi also sets him for a strong opposition from supporters of Shafiq, viewed as a representative of the old regime.
Naguib Sawiris, a Coptic Christian business tycoon who joined a liberal bloc in voicing opposition to the Muslim Brotherhood a day before the results were announced, said he expects the new president to send a reassuring message to Egypt's Christian minority who represent around 10 percent of the population of 85 million.
"There are fears of imposing an Islamic state ... where Christians don't have same rights," Sawiris told the private TV station CBC. Morsi "is required to prove the opposite. ... We don't want speeches or promises but in the coming period, it is about taking action. ... He was not our choice but we are accepting it is a democratic choice."
Hamdeen Sabahi, a leftist presidential candidate who came in a surprising third place in the first round of elections, asked Morsi to live up to his pledges to form a national coalition government and appoint presidential aides from different groups "that express the largest national consensus."
Khaled Abdel-Hamid, a leading leftist politician, said Morsi must fight to get his powers back or he will lose any popular support he may have garnered.
"If he fights to get his power back, we will support him. But if he doesn't fight back, then he is settling for siding with the military," he said.