By Tom Perry and Alexander Dziadosz
CAIRO, July 8 (Reuters) - At least 42 people were killed on Monday when 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 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 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 that 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.
SHOTS DURING PRAYERS
Abdelaziz Abdelshakua, from Sharqia Province northeast of Cairo, was wounded in his right leg with what he says was a live round.
"We were praying the dawn prayer and we heard there was shooting," he said, adding an army officer assured them no one was shooting, then suddenly they came under fire from the direction of the Republican Guard.
"They shot us with teargas, birdshot, rubber bullets -- everything. Then they used live bullets."
A Reuters journalist at the scene saw first aid helpers attempting mouth-to-mouth resuscitation on a dying man.
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 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.
The military overthrew Morsi on Wednesday after mass nationwide demonstrations led by youth activists demanding his resignation. The Brotherhood denounced the intervention as a coup and vowed peaceful resistance.
Talks on forming a new government were already in trouble before Monday'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.
Scenes of running street battles between pro- and anti-Mursi demonstrators in Cairo, Alexandria and cities across the country have alarmed Egypt's allies, including key aid donors the United States and Europe, and Israel, with which Egypt has had a U.S.-backed peace treaty since 1979.
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.
On Sunday, huge crowds numbering hundreds of thousands gathered in different parts of Cairo and were peaceful, but nonetheless a reminder of the risks of further instability.
For many Islamists, the overthrow of Egypt's first freely elected president was a bitter reversal that raised fears of a return to the suppression they endured for decades under autocratic rulers like Mubarak.
On the other side of the political divide, millions of Egyptians were happy to see the back of a leader they believed was orchestrating a creeping Islamist takeover of the state - a charge the Brotherhood has vehemently denied.
Washington has not condemned the military takeover or called it a coup, prompting suspicion within the Brotherhood that it tacitly supports the overthrow.
Obama has ordered a review to determine whether annual U.S. assistance of $1.5 billion, 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 percent of its value since late last year.