It was the culmination of the tumultuous first phase of a transition launched 16 months ago with the uprising that ousted autocratic leader Hosni Mubarak, who was replaced by a ruling military council headed by Mubarak's defense minister of 20 years. It is the start of a new struggle with the military to restore the powers that the ruling generals stripped from the presidency even before the victor was declared.
And it was not the outcome desired by most of the liberal and secular youth groups that drove the uprising.
"The revolution passed an important test," said Yasser Ali, a spokesman for Morsi's campaign. "But the road is still long."
Morsi now has to calm public fears that he will push to remake Egypt as an Islamist state and show that he will represent a broader swath of the public beyond his own fundamentalist group, the Muslim Brotherhood. He will also have to try to urgently address the major problems facing Egypt, a sharp deterioration in security and a flailing economy.
Morsi narrowly defeated Mubarak's last prime minister Ahmed Shafiq with 51.7% of the vote versus 48.3, the election commission said. Turnout was 51%.
Just one week ago, at the moment polls were closing in the runoff election, the ruling generals issued constitutional amendments that stripped the president's office of most of its major powers. They 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.
A few days before that constitutional declaration, a court dissolved the freely elected parliament, which is dominated by the Muslim Brotherhood.
A huge crowd of Morsi supporters celebrated in Cairo's Tahrir Square, the birthplace of the uprising, as soon as the result was announced on live television. Some released doves with Morsi's pictures over the square and others set off fireworks.
Morsi's spokesman Ahmed Abdel-Attie said words cannot describe the "joy" in this historic moment.
"We got to this moment because of the blood of the martyrs of the revolution," he said at a news conference after the results were announced. "Egypt will start a new phase in its history."
The country's last four presidents over the past six decades have all came from the ranks of the military. This is the first time modern Egypt will be headed by an Islamist and by a freely elected civilian.
"Congratulations because this means the end of the Mubarak's state," said Shady el-Ghazali Harb, a prominent activist who was among the leaders of the protests in January and February last year.
Farouk Sultan, the head of the commission, described the elections as "an important phase in the end of building our nascent democratic experience."
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.
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.
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.
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 who fear the domination of the Brotherhood. 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.
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 does fight back, then he is settling for siding with the military," he said.
Protesters in Tahrir have said they will not leave the square, in which they have been holding a sit-in for nearly a week, until Morsi can restore his rightful powers.