Media playback is unsupported on your device Media caption 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.

Speaking later in a TV address, Mr Mursi hailed a "historic day" for the nation, and said he would be a president for all Egyptians.

There have been scenes of jubilation in Cairo's Tahrir Square, where Mr Mursi's supporters gathered.

Analysis The Islamists' rise to power in Egypt will send shockwaves through the courts and palaces of conservative Arab kings and presidents who have tried for decades to put the lid on political Islam. But foremost among Egypt's neighbours who watched the brotherhood's success with increasing alarm is Israel. Cairo was the first Arab state to sign a peace treaty with Israel and the brotherhood has traditionally been vehemently opposed to that. But its opposition has softened over the years - at least publicly. It is widely believed that the Muslim Brotherhood have reassured Washington that an Islamist government in Egypt would respect the peace deal with Israel. Given also that the ruling military council will continue to have the final say on matters of war and peace, it is unlikely that the brotherhood can put that peace at risk. It is also more likely that Mr Mursi's immediate priority will be to concentrate on Egypt's many daunting domestic problems including rampant poverty and unemployment.

They have been holding a vigil there for days in protest at a 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.

As night fell, tens of thousands continued to throng Tahrir Square. Mr Mursi was due to address the nation in his first speech after being declared president.

"Down with military rule" his supporters chanted amid wild cheering and explosions of fireworks after the result was announced

Across Cairo, cars sounded their horns amid crowds chanting "Mursi, Mursi".

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.

'Unity and love'

Media playback is unsupported on your device Media caption Mohammed Mursi: ''The revolution goes on"

Mr Mursi thanked God and "the blood, tears and sacrifices" of his fellow countrymen.

"Today I am a president for all Egyptians, wherever they may be," he said.

"Thanks to our unity and our love for each other, we will able to make a respectable future for ourselves."

The president-elect saluted the "martyrs of the revolution", which last year swept away the authoritarian rule of Hosni Mubarak.

But he also praised the army and police, who many Egyptians see as playing negative roles over the past year.

The BBC's Kevin Connolly in Cairo says Mr Mursi's victory is a moment of profound change for Egypt.

The Muslim Brotherhood, that has seen many of its members put in prison, now has one of its leaders being sent instead to the presidential palace, he says.

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.

UK Foreign Secretary William Hague also congratulated Mr Mursi, saying it marked "an historic moment for Egypt".

A White House statement said: "We believe it is essential for the Egyptian government to continue to fulfil Egypt's role as a pillar of regional peace, security and stability.

Mohammed Mursi Aged 60, married with four children

Comes from a village in the Nile Delta province of Sharqiya

US-educated engineering professor; teaches at Zagazig University

Rose through the ranks of the Muslim Brotherhood

Has been praised for his oratory as an MP

After toppling of Hosni Mubarak, he became chairman of Brotherhood's FJP party Profile: Mohammed Mursi

Israeli Prime Minister Benjamin Netanyahu said he hoped the long-standing peace treaty between the two countries would continue.

Hours after the result, Mr Mursi resigned from his positions within the Muslim Brotherhood including his role as chairman of its Freedom and Justice Party (FJP) as he had pledged to do in the event of his victory.

Mr Mursi has promised that his leadership will be inclusive, and has courted secular and Christian voters.

Earlier, the head of the Higher Presidential Election Commission, Farouq Sultan, began the news conference by saying the declaration of the result had been "marred by tension and a bad atmosphere".

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

The military council has ruled Egypt since last year's revolution that toppled former president Hosni Mubarak, and has promised to oversee a transition to democracy.

However, a series of decrees has led many to believe it intends to cling on to power.

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.

Image caption Troops were deployed outside the offices of the Higher Presidential Election Commission

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.