More than 31 people were killed and at least 400 wounded in Tripoli, Libya, after militiamen opened fire on street demonstrators.

The bloodshed began on Friday when Prime Minister Ali Zeidan demanded that all militias leave Tripoli.

Militiamen from the city of Misrata fired on 500 protesters who were demanding their eviction from the capital. This was some of the worst street fighting in the Libyan capital since the overthrow of Muammar Gaddafi.

A Reuters reporter witnessed an anti-aircraft cannon firing into the crowd from the Ghargur brigades gated compound, while protesters chanted: "We don't want armed militias!"

"The demonstration was peaceful and had been permitted by the interior ministry, and then the protesters were fired on when they entered the Gharghur district," where the headquarters of the militia are located, Zeidan told Reuters.

The Libyan government has been struggling to contain the numerous militias that control many parts of the country.

Airforce planes circled overhead during the clashes. "We want to make sure the militia don't bring in any reinforcements," said army spokesman Ali al-Sheikhi.

At least 32 people were killed and 391 wounded, a Health Ministry official said. A Reuters reporter saw the body of a girl, aged around 12, whose head had been almost blown off.

Prime Minister Zeidan blamed TV stations for inflaming the situation and advised them to exercise control over who was speaking on TV, since Libya did not have "a stable democratic situation" which would allow for freedom of expression.

The Libyan PM is struggling to control rival militias, Islamist militants and other former fighters who refuse to give up their arms two years after helping to oust Gaddafi in a Nato-backed revolt.

The authorities have tried to pacify the militias by placing them on the government payroll and giving them security assignments.

But the gunmen often remain loyal to their own commanders and fight for control of local areas, especially those with lucrative weapons or drug smuggling rackets, or use violence to settle personal feuds.