Mohammed Mursi is declared the winner of Egypt's presidential election
The Muslim Brotherhood's Mohammed Mursi has been declared the winner of Egypt's presidential election run-off.
He won 51.73% of the vote, beating former PM Ahmed Shafiq, the Higher Presidential Election Commission said.
The head of the panel of judges, Farouq Sultan, said it had upheld some of the 466 complaints by the candidates, but that the election result still stood.
The announcement prompted scenes of jubilation in Cairo's Tahrir Square, where Mr Mursi's supporters gathered.
They have been maintaining a vigil there for days in protest at the series of decrees by the ruling Supreme Council of the Armed Forces (Scaf) which they say are designed to reduce or constrain the power of the president, and entrench the power of the military.
"Down with military rule" they chanted amid wild cheering and explosions of firecrackers.
Across Cairo, cars sounded their horns amid crowds chanting "Mursi, Mursi".
'Campaigns of scepticism'
Supporters of Mr Shafiq, who had been holding a rally in the capital's northern suburb of Nasser City, were stunned by the result.
There was screaming and crying and people were seen holding their heads in despair.
Security had been tight for the announcement, with tanks and troops deployed around the election commission's headquarters.
Egypt's military ruler, Field Marshal Hussein Tantawi, congratulated Mr Mursi on his victory, state-run Nile News TV reported.
Earlier, Judge Sultan began the news conference by saying the declaration of the result had been "marred by tension and a bad atmosphere".
"The commission applied the law when it looked into the ballots. There is nothing above the law," he asserted.
The judge then dismissed what he said had been the two most serious complaints of electoral violations - that some ballots had been printed with the name of one candidate already ticked, and that Christians had been prevented from voting in a village in Minya governorate.
He then spent several minutes announcing minor amendments to the vote tallies before suddenly revealing that Mr Mursi had won 13,230,131 votes (51.73%), compared with Mr Shafiq's total of 12,347,380, or 48.27%.
The turnout in last weekend voting was 51.58%, he added.
As Judge Sultan announced the victory of Mr Mursi, who is chairman of the Muslim Brotherhood's Freedom and Justice Party (FJP), huge cheers erupted in Tahrir Square.
Tens of thousands of his supporters, as well as those of ultra-conservative Salafist groups, had gathered there to watch the result on big screens.
Many had camped out overnight to protest against what Islamists, secularists and youth activists have denounced as a military coup.
On 13 June, the justice ministry gave soldiers the right to arrest civilians for trial in military courts until the ratification of a new constitution.
The Scaf then issued a decree on Friday dissolving parliament in line with a Supreme Constitutional Court ruling that the law on elections to the lower house was invalid because party members had been allowed to contest seats reserved for independents.
Two days later, just as the polls were closing in the run-off, the generals issued an interim constitutional declaration that granted them legislative powers and reinforced their role in the drafting of a permanent constitution. The military was also exempted from civilian oversight.
Then on Monday, Field Marshal Tantawi announced the re-establishment of a National Defence Council, putting the generals in charge of Egypt's national security policy.
The generals have vowed to hand over power to the new president by 30 June, but their decision to dissolve parliament means Mr Mursi could take office without the oversight of a sitting legislature and without a permanent constitution to define his powers or duties.