The tense stand off at the Al-Fath mosque came after bloody clashes that killed 83 people across the country and resulted in the arrest of more than 1,000 alleged supporters of Morsi's Muslim Brotherhood.
The crackdown has divided Egyptians as never before in recent history, splintering the army-installed government and inviting international censure.
One protester said nearly 1,000 people were trapped in the mosque, which had earlier held the bodies of more than 20 people killed in Friday's clashes.
Soldiers had offered to evacuate the women but insisted on questioning the men, which the protesters refused, a demonstrator on the scene said.
Both sides accused the other of opening fire but the gunfire then ended, one person inside the mosque told AFP.
"Thugs tried to storm the mosque but the men barricaded the doors," she said.
Security officials quoted by the official MENA news agency said that "armed elements" had been shooting at security forces and police from inside the mosque.
Morsi's Freedom and Justice Party (FJP) pleaded for another "massacre" to be avoided after at least 578 people were killed across the country Wednesday when police cleared protest camps set up by loyalists of the former president deposed by the military on July 3.
It was not possible to verify the numbers in the mosque independently.
The latest unrest started as Morsi supporters emerged from mosques in the capital to protest in what they billed as a "Friday of anger" following Wednesday's bloodbath.
Violence erupted almost immediately, with gunshots ringing out in Cairo and security forces firing tear gas.
In the capital, a man leapt off a bridge near a police station to escape shooting as police armoured vehicles advanced on protesters, witnesses said.
An AFP correspondent counted at least 19 bodies in one Cairo mosque, while witnesses said more than 20 corpses had been laid out in a second mosque.
Elsewhere in Egypt, 10 people were killed by security forces and dozens injured in the canal city of Suez when they gathered to protest in defiance of the curfew.
Their deaths brought to 83 the number killed in nationwide violence although the FJP spoke of 130 dead in Cairo alone.
Marches were also reported in the Mediterranean city of Alexandria, in Beni Sueif and Fayyum, south of Cairo, and in the Red Sea resort town of Hurghada.
The demonstrations ended shortly after a night-time curfew came into effect but Anti-Coup Alliance spokesman Gehad El-Haddad told AFP that Morsi loyalists would hold "daily anti-coup rallies" going forward.
The interior ministry said in a statement early Saturday that "the number of Muslim Brotherhood elements arrested reached 1004," including 558 in Cairo alone.
The Egyptian cabinet issued a defiant statement after the unrest, saying it was confronting a "terrorist plot."
"The cabinet affirms that the government, the armed forces, the police and the great people of Egypt are united in confronting the malicious terrorist plot by the Muslim Brotherhood," it said.
And the interior ministry, which authorised police to use live fire if government buildings came under attack, accused the Brotherhood of attacking police stations, saying it foiled attempts to storm buildings.
Meanwhile, in Jordan, Morocco and the Palestinian territories, hundreds joined demonstrations in support of the Brotherhood.
And Egypt continued to defend the crackdown, announcing it was cancelling naval exercises with Turkey to protest Ankara's condemnation.
Turkey, which backs Morsi, has recalled its ambassador to Cairo over the violence, prompting a tit-for-tat move by Egypt.
The EU's foreign policy chief said the violence was "shocking".
"I have asked member state representatives to debate and coordinate appropriate measures to be taken by the European Union in response to the situation in Egypt," said Ashton.
French President Francois Hollande on Friday discussed the crisis with counterparts in London, Berlin and Rome.
Germany said it would review ties with Cairo, and joined France and Britain in calling for EU talks on the situation, which are expected to take place on Monday.
On Thursday, the UN Security Council held an emergency meeting on Egypt, calling for an end to the violence and "national reconciliation".
The UN said it would dispatch Jeffrey Feltman, under secretary general for political affairs, to Cairo next week.
President Barack Obama said the US was cancelling a joint US-Egyptian military exercise, but he stopped short of suspending Washington's annual $1.3 billion in aid.
Human rights organisation Amnesty International called for a full and impartial investigation into the bloodshed in Egypt, saying the authorities' response to the protests has been "grossly disproportionate".
And Venezuelan President Nicolas Maduro recalled his ambassador to Cairo and called for Morsi to be reinstated.
However, the international response was not uniformly critical, with Saudi Arabia and Jordan saying they backed Egypt's fight against "terrorism".
King Abdullah said Saudi Arabia stood "with its Egyptian brothers against terrorism, deviance and sedition, and against those who try to interfere in Egypt's internal affairs".