Hamza Hendawi, Sarah El Deeb and Maggie Michael / The Associated Press

CAIRO — Egypt’s military gave a “last-chance” ultimatum Monday to President Mohammed Morsi, giving him 48 hours to meet the demands of millions of protesters in the streets seeking his ouster, or the generals will intervene and impose their own plan for the country. Army helicopters swooped over Tahrir Square trailing Egyptian flags, to the cheers of the crowd opposed to the Islamist leader.

The military’s statement, read on state TV, put enormous pressure on Morsi to step down. Giant crowds demanding his departure in cities around the country for a second straight day erupted into delirious parties of celebration, with men and women dancing, and some crying as patriotic songs blasted from speakers on cars.

But any army move against Morsi after the two-day deadline risks a backlash from Morsi’s Islamist backers, including his powerful Muslim Brotherhood and hard-liners, some of whom belong to former armed militant groups.

After the army statement, multiple officials of Morsi’s Muslim Brotherhood insisted that the military and street protests cannot overturn the legitimacy of the president’s election. An alliance of the Brotherhood and other Islamists read as statement at a televised press conference calling on all people “to rally in defense of legitimacy and reject any attempt to overturn it.”

Pro-Morsi marches numbering in the several thousands began after nightfall in a string of cities around the country. In Cairo, thousands of Islamists massing outside a mosque near the Ittihadiya presidential palace reacted with shock and fury to the military announcement, some vowing to fight against what they called a coup against the “Islamist project.”

“Any coup of any kind against legitimacy will only pass over our dead bodies,” one leading Brotherhood figure, Mohammed el-Beltagi, told the rally. A line of around 1,500 men with shields, helmets and sticks — assigned with protecting the rally against attackers — stamped their feet in military-like lines, singing, “Stomp our feet, raise a fire, Islam’s march is coming.”

Army troops at checkpoints on roads leading to the pro-Morsi rally checked cars for weapons, after repeated reports some Islamists were arming themselves.

The army’s stance also raises a unsettling prospect for many of Morsi’s opponents as well — the potential return of the military that ruled Egypt directly for nearly 17 months after the Feb. 11, 2011 fall of autocrat Hosni Mubarak. During that time, many of those now in the anti-Morsi campaign led protests against military rule, angered by its management of the transition and heavy hand, including killings of protesters.

Even many who welcomed Monday’s announcement expressed worries over a possible outright military takeover.

“Morsi will leave, but I’m concerned with the plan afterward. The military should be a tool to pressure, but we had a bitter experience with military ruling the country and we don’t want to repeat it,” said Roshdy Khairy, a 24-year-old doctor among the throngs in Tahrir Square Monday night.