Ali Mohamed Gedi, the head of Somalia's interim government, on Friday entered Mogadishu amid protests by thousands over the presence of Ethiopian troops in the capital.
Gedi travelled into Mogadishu in a high security convoy, protected by about 100 Ethiopian soldiers, one day after the leaders of Islamic courts forces left the city.
Gedi's government, whose fighters forced the Islamic courts out with the help of the Ethiopian military, plans to enforce three months of martial law in a bid to reestablish order.
Looting and gunbattles erupted between rival clan-based militias erupted.
Protestors, chanting anti-Ethiopian slogans, threw stones and burnt tyres as the prime minister headed into the capital. Hundreds of Ethiopian troops, and tanks, were already in the city.
"Thousands of angry people have started a violent demonstration in the northern part of the city, particularly in Tawfiq and Suuqaholaha areas," said one resident Abdulsatar Dahir Sabrie.
Gedi said martial law was needed to disarm all the militias.
Speaking to reporters late Thursday in his home village of Mundul Sharey, north of the capital, Gedi said: "This country has been through a lot of anarchy, so to restablish order we will have to have an iron hand, especially with the private militia."
Deputy Prime Minister Hussein Mohamed Aidid said the parliament based in Baidoa is expected to endorse the move on Sunday.
The transitional government-Ethiopian alliance had been fighting the Islamic courts for control of the country since December 20. The conflict erupted after Ethopia rejected an Islamist demand to withdraw from Somalia.
Islamic courts fighters still held the southern port town of Kismayo, where one of their senior commanders vowed they would launch hit-and-run attacks across the country.
Dinari said Mogadishu elders had assured the government of their support, but uncertainty still prevailed in the town. Many Islamic courts fighters, who swapped their uniforms for civilian clothes and removed their turbans, roamed the streets.
Islamic courts fighters said their leader Sheikh Hassan Dahir Aweys was in Kismayo about 500 kilometres (300 miles) south of the capital, where residents reported Ethiopian jets flying over the region, apparently on reconnaissance missions that raised fears of bombing.
"We will never surrender to Ethiopians and the government of (President) Abdullahi Yusuf Ahmed," local Islamic courts’ commander Sheikh Mohamed Ibrahim Bilal said from Kismayo.
"I assure you the Islamic forces are everywhere in the country and you will see the forces operating within days. What we will do is hit and run. We will ambush their convoys everywhere in Somalia."
Somalia fought wars against Ethiopia in 1964 and in 1977/78. But Ethiopia said its intervention was necessary as the Islamic courts were a security threat.
"We do not need and clearly we do not welcome Ethiopian forces here or anywhere in Somalia," said resident Muhamoud Abdi.
A correspondent saw Ethiopian tanks, more than 70 military trucks and hundreds of troops near Banadir Hospital in southern Mogadishu. Hundreds more vehicles were parked at the northern and western gates of the city.
Meanwhile, the UN World Food Programme said it would resume humanitarian air operations to Somalia this weekend after the government lifted a ban on air flights.
Somalia disintegrated into lawlessness after the 1991 ouster of dictator Mohamed Siad Barre. It was carved up among clan warlords, some of whom now back the government, and defied all international bids to restore functioning institutions of state.
There have been no independent assessments of casualties but Ethiopian Prime Minister Meles Zenawi claimed up to 3,000 dead on the side of the Islamic courts, while the Islamists said they had killed hundreds of government troops.
The Ethiopian intervention in Somalia has received tacit US support, with Washington arguing that Addis Ababa had legitimate security.