At least 51 people have been killed after Islamist demonstrators enraged by the military overthrow of Egypt's elected president Mohamed Mursi said the army opened fire during morning prayers at the Cairo barracks where he is being held.

But the military said a terrorist group tried to storm the Republican Guard compound and one army officer had been killed and 40 wounded. Soldiers returned fire when they were attacked by armed assailants, a military source said.

The emergency services said more than 320 were wounded in a sharp escalation of Egypt's political crisis, and Mr Mursi's Muslim Brotherhood urged people to rise up against the army, which they accuse of a military coup to remove the elected leader.

At a hospital near the Rabaa Adawia mosque where Islamists have camped out since Mr Mursi was toppled on Wednesday, rooms were crammed with people wounded in the violence, sheets were stained with blood and medics rushed to attend to the wounded.

As an immediate consequence, the ultra-conservative Islamist Nour party, which initially backed the military intervention, said it was withdrawing from stalled negotiations to form an interim government for the transition to fresh elections.

The military has said the overthrow was not a coup, and it was enforcing the will of the people after millions took to the streets on June 30 to call for his resignation.

But pro and anti-Mursi protests took place in Cairo, Alexandria and other cities, and resulted in clashes on Friday and Saturday that left 35 dead.

It leaves the Arab world's largest nation of 84 million people in a perilous state, with the risk of further enmity between people on either side of the political divide while an economic crisis deepens.

Al Jazeera's Egypt channel showed footage from inside a makeshift clinic near the scene of the violence, where Mursi supporters attempted to treat bloodied men.

Seven dead bodies were lined up in a row, covered in blankets and an Egyptian flag. A man placed a portrait of Mr Mursi on one of the corpses.

Footage broadcast by state TV showed Mursi supporters throwing rocks at soldiers in riot gear on one of the main roads leading to Cairo airport. Young men, some carrying sticks, crouched behind a building, emerging to throw petrol bombs before retreating again.

State-run television showed soldiers carrying a wounded comrade along a rock-strewn road, and news footage zoomed in on a handful of protesters firing crude handguns during clashes.

The rest of the city was for the most part calm, though armoured military vehicles closed bridges over the Nile to traffic following the violence.

Talks on forming a new government were already in trouble before yesterday's shooting, after the Nour Party rejected two liberal-minded candidates for prime minister proposed by interim head of state Adli Mansour.

Nour, Egypt's second-biggest Islamist party, which is vital to give the new authorities a veneer of Islamist backing, said it had withdrawn from the negotiations in protest at what it called the "massacre at the Republican Guard (compound)".

"The party decided the complete withdrawal from political participation in what is known as the road map," it said.

The military can ill afford a lengthy political vacuum at a time of violent upheaval and economic stagnation.

The violence has also shocked Egyptians, growing tired of the turmoil that began two-and-a-half years ago with the overthrow of autocrat Hosni Mubarak in a popular uprising.

In one of the most shocking scenes of the last week, video footage circulated on social and state media of what appeared to be Mursi supporters throwing two youths from a concrete tower on to a roof in the port city of Alexandria.

The images, stills from which were published on the front page of the state-run al Akhbar newspaper on Sunday, could not be independently verified.

Washington has not condemned the military takeover or called it a coup, prompting suspicion within the Brotherhood that it tacitly supports the overthrow.

BarackObama has ordered a review to determine whether annual US assistance of $1.5 billion (£1bn), most of which goes to the Egyptian military, should be cut off as required by law if a country's military ousts a democratically elected leader.

Egypt can ill afford to lose foreign aid. The country appears headed for a looming funding crunch unless it can quickly access money from overseas. The local currency has lost 11% of its value since late last year.