Video sent to Reuters from an anti-government demonstration showed civilians in facemasks waving Somali flags scattering as gunfire erupted. Reuters journalists nearby could hear intermittent gunfire as well as heavier explosions.
"Many forces heavily attacked us, I am now on my chest in an alley. This is a massacre," protester Farah Omar told Reuters by phone.
The spillover of political rivalries into open conflict will dismay Somalia's allies and play into the hands of the al Qaeda-linked al Shabaab insurgency, which mounts attacks on civilians around East Africa in its bid to install strict Islamic law.
Prominent opposition figure Abdirahman Abdishakur Warsame Wadajir had earlier posted a video of himself leading a small crowd of protesters into the street, in defiance of a government ban on demonstrations.
Hours before that, Somalia's former president, Sheikh Sharif Sheikh Ahmed, accused government troops of attacking a hotel where he was staying with another former president ahead of Friday's rally.
"Tonight, Farmajo attacked us with armoured vehicles. That is dictatorship. He attacked us and residents at Maida hotel," Ahmed tweeted after the attack, referring to President Mohammed. "We ask all civilians to come out and respond."
Somalia's minister of security Hassan Hundubey Jimale accused the opposition of starting the fighting.
"Armed militia attacked government forces. We repulsed and overpowered the militias," Jimale said in an overnight statement.
Without mediation, the fighting has the potential to spread quickly.
Somalia has been riven by civil war since 1991 and both the government and opposition can call on heavily armed supporters. Legislators often travel in vehicles armed with anti-aircraft guns.
Somali lawmakers were due to select a new president on Feb 8, but the process was delayed after the opposition accused the government of packing regional and national electoral boards with supporters.
Somalia's opposition alliance has said that Mohammed's term has expires and he is no longer president.
Mogadishu resident Ahmed Aden, 44, told Reuters on Friday he had to flee during the night's gunbattles.
"Last night we took our children and mattresses on our shoulders and fled before war started," he said. "We returned at gunpoint. Turkish-made armoured vehicles and government forces blocked every road and alley."