Somali President Sheikh Sharif Sheikh Ahmed joined his troops on the front lines Wednesday night as they fought Islamist militants in the capital.
Witnesses and officials say the president, dressed in military fatigues, was stationed with Somali government forces and African Union peacekeepers.
One presidential aide said Mr. Sharif was armed with an AK-47 rifle.
At least seven people were killed in Mogadishu late Wednesday as government forces traded shell and gunfire with al-Shabab insurgents.
Mr. Sharif was unhurt in the fighting, but a journalist told VOA's Somali Service that a mortar shell landed about a third of a kilometer away from the president.
Mr. Sharif, a moderate Islamist, was elected by parliament 18 months ago to lead Somalia's fragile transitional government.
The government controls only small parts of the capital after a three-and-a-half-year Islamist insurgency.