Mohammed Morsi of the Muslim Brotherhood has defeated former prime minister Ahmed Shafiq in Egypt's disputed presidential runoff vote.

On Sunday, the Egyptian election commission declared Morsi winner of the country's first free elections by a narrow margin over Shafiq, the last prime minister under deposed leader Hosni Mubarak.

The commission said Morsi won with 51.7 per cent of the vote versus 48.3 for Shafiq.

A huge crowd of Morsi supporters who filled Cairo's Tahrir Square erupted in cheers and dancing when the result was read out on live television. Fireworks blasted overhead as flags waved amid the celebrations.

“I pledge to be a president who serves his people and works for them,” Morsi wrote on his official website.

“I will not betray God in defending your rights and the rights of this nation.”

Morsi was expected to speak to the nation Sunday night in his first speech since being elected 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.

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.

Morsi spokesman Ahmed Abdel-Attie said words can't 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's victory was the culmination of a tumultuous, 16-month transition that was supposed to bring democratic rule to Egypt.

But that transition was tightly controlled and curtailed by military rulers who took power from Mubarak.

For Egypt's new president, it will be a tough battle to wrest any formative constitutional powers from the country's military elite.

"The military is still going to enjoy quite a strong hand in the Morsi administration," Wall Street Journal correspondent Matt Bradley told CTV News Channel Sunday.

Last Sunday, as the polls were closing, the military announced a constitutional change that increased their legislative authority.

That change came about after the country's top court tossed out earlier parliamentary elections.

The Muslim Brotherhood dominated those elections, but because the constitution required a certain number of candidates to be independent, the vote was nullified, raising suspicions the military was building power ahead of the presidential results.

"They (military) made a lot of the president's responsibilities contingent on military approval, including a body that was set to draft a new constitution," Bradley said in a telephone interview from Cairo.

It will be up to Morsi's party and support from within the ranks of the revolutionary youth groups who led the uprising that ousted Mubarak, to challenge the military and press their democratic demands, he said.

It's likely Shafiq will challenge the tight election results, but he may find that a difficult road to follow, Bradley said.

"The commission which is regulating the vote and leading it . . . their rule is the final rule as stipulated by a constitutional declaration made the military," he said.