The situation remained confused later Sunday with sporadic gunfire heard and troops blocking all major roads.
Several dozen opposition supporters earlier marched in protest against President Mohamed Abdullahi Mohamed, better known as Farmajo, whose legal authority has been in doubt since February when his four-year term expired before fresh presidential elections were held.
"Some clan militiamen organised by opposition politicians tried to disturb peace in Mogadishu, they have advanced onto police checkpoints... but the security forces took immediate action against them," police commander Mohamed Abdirahman said.
"The security forces are now in full control of the situation," he added.
A second exchange occurred later nearby. It was not yet known if there were any casualties.
There was also a confrontation in the area where former president Hassan Sheik Mohamud, another opposition leader, lives.
"It is unfortunate that forces loyal to the president whose mandate expired attacked my house, I have previously warned about politicalising the security and I repeat it. Farmajo will take responsibility for the consequence of these acts," he said on Twitter.
Witnesses denied that his home was attacked, as did the Ministry of Internal Security which in a statement said: "Earlier today, our forces foiled several attempted attacks against the public and shut down the organised militia who entered the capital with an aim of instilling fear and panic among the public."
Later Sunday, sporadic gunfire was heard in the capital although the source was unclear.
'Highly concerned'
In a video tweeted by a government spokesperson, Prime Minister Mohamed Hussein Roble said he was "deeply saddened by the tragedy that has disrupted security in the capital".
"I believe that dialogue is the best option to us, a process that I have started and hoping to succeed," he added.
Britain's embassy in Mogadishu and the EU's envoy Nicolas Berlanga expressed alarm.
"Highly concerned about the ongoing events in Mogadishu," Berlanga said on Twitter.
"The general interest requests maximum restraint, preserve institutions that belong to all and dialogue. Violence is unacceptable. Those responsible will be held accountable."
In April, a bill extending the president's authority by two years bypassed the Senate after being adopted by the lower house of parliament.
Read more: Somali president signs law extending mandate for two years
Opposition parties condemned the move as an unconstitutional bid to cling to power, and the law was criticised by the international community.
The president and leaders of Somalia's five semi-autonomous federal states had reached an agreement in September that paved the way for indirect parliamentary and presidential elections in late 2020 and early 2021.
But it fell apart as squabbles erupted over how to conduct the vote, and multiple rounds of talks have failed to break the impasse.
On Friday, the African Union condemned the extension of the president's mandate.
The UN Security Council also adopted a statement calling on parties in Somalia "to reject violence and resume dialogue as a matter of urgency and without precondition," underscoring its concern over the country's political crisis.
Follow us on Facebook, Twitter and Instagram to stay connected