Muslim Brotherhood candidate Mohammed Morsi has won Egypt's presidential runoff, the country's election commission said Sunday.
Morsi's supporters, packed into Tahrir Square, were seen celebrating, dancing and waving flags after the result was announced on live television.
Some released doves with his pictures over the square where the uprising that ousted Mubarak last year was born. 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. "Egypt will start a new phase in its history."
Morsi won by a narrow margin over Ahmed Shafiq, the last prime minister under deposed leader Hosni Mubarak. The commission said Morsi took 51.7 percent of the vote versus 48.3 for Shafiq.
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.
Earlier Sunday, Egyptian police were ordered to confront any attempt to break the law with decisive force ahead of the results being announced, as soaring tensions in the country raised fears of a new outbreak of political violence.
The results of Egypt's first free presidential vote had been delayed for several days, giving way to wild rumors, speculation and anxiety about back room deals and suspected interference by the ruling military council in determining the outcome in favor of Shafiq.
Shafiq and Morsi had both declared that they won what was by all accounts a very close race.
The announcement of the president was supposed to be the end of Egypt's post-uprising transition to democracy. However the military made a series of last minute moves that stripped the office of president of most of its major powers and kept those powers concentrated in the hands of the military. A court ruling a few days before that dissolved the freely elected parliament that was dominated by the Muslim Brotherhood.
A military official told The Associated Press late Saturday: "This time, we won't be kidding. We were kind ... before" with lawbreakers, adding that a curfew can be imposed if needed. He spoke on condition of anonymity because he was not authorized to speak to the media.
On Saturday, authorities deployed extra security forces across the country, especially near key state institutions. Government and private sector employees were sent home early on Sunday, while many Egyptians stocked up on food and jewelry shops shut down because of concerns over new violence.
Armored vehicles and troops were deployed at exits and entrances to Cairo airport. Riot police clad in black uniforms with shields were deployed around parliament and the streets leading to the Cabinet building nearby were blocked by troops and armored vehicles.
Minister of Interior Gen. Mohammed Ibrahim, who is in charge of police and other security forces, ordered top security officers in a meeting Saturday that police should "confront with firmness, force and decisiveness any attempt to violate" the law, according to a security official. The official spoke on condition of anonymity because he was not authorized to speak to the media.
"Neither Morsi, nor Shafiq, Tantawi is the president of Egypt," read one headline of the weekly Sout el-Umma in a reference to the head of the ruling military council, Field Marshal Hussein Tantawi. Tantawi was Mubarak's defense minister for 20 years.
The election outcome will not put an end to the main power struggle in the country now between Morsi's Muslim Brotherhood and the military.