Tripoli, Libya (CNN) -- At least 31 people were killed and nearly 300 injured on Friday in the bloodiest day in the Libyan capital since the fall of Tripoli in 2011, according to figures released by the government.
Fighting broke out after protesters marched on the Tripoli headquarters of militias from the coastal city of Misrata.
Protesters and eyewitnesses said militiamen opened fire on the hundreds who marched on Gharghour, a southern district of the capital where Misrata militia are based, in an effort to evict the armed groups.
TV footage aired on the privately owned al-Nabaa channel showed militiamen, in what appeared to be an antiaircraft cannon mounted on a truck, opening fire directly at protesters.
The situation escalated into an armed confrontation that lasted for hours as protesters returned with weapons and militiamen from different parts of the capital.
The sound of heavy gunfire, artillery and explosions echoed across Tripoli after nightfall.
The scene at Tripoli's overwhelmed hospitals was one of chaos and grief, as women wailed and a constant stream of ambulances delivered injured men, women and children.
"The scenes in trauma hospitals across Tripoli resembled a war zone tonight: frantic health staff rushing to provide help, armed men nervously patrolling corridors, and families desperately trying to find their loved ones " Said Hanan Salah, a Libya researcher for Human Rights Watch, who visited a number of the capital's main hospitals.
In a statement released on Friday night, the Libyan government described the protest as a "peaceful" event that came under fire when it entered Gharghour.
"The government asked the people to go out and protest across the country to reject armed brigades in cities, especially in Tripoli. We salute the peaceful protest that came out today, it was an unarmed protest that had obtained the government's permission" the statement said.
A commander of a Misrata militia speaking by phone to state TV claimed that protesters had opened fire first and one militiaman was killed from gunshots he said came from nearby rooftops.
Al-Taher Basha Agha said the armed groups had agreed to leave the capital once the country's constitution was passed, but Friday's violence had changed their position.
"By God, we will not leave, we will only leave in our coffins," the commander said.
Militiamen from Misrata and a number of other Libyan cities came into Tripoli during the fight for the capital in August 2011 and have created bases in different parts of the capital where they have remained since.
Friday's protest partly organized by the Tripoli Local Council comes after heavy fighting in the heart of the capital last week between the Misrata militiamen and other groups from Tripoli.
Anger against the various militias has been mounting for months in Tripoli and other Libyan parts of the country, including the eastern city of Benghazi that has been gripped by increasing violence, including political assassinations.
Libya's weak central government has not been able to rein in militia groups with various regional, tribal and political loyalties. The government has been struggling with its plans to build an army and police. Many militia are on the state's payroll but continue to operate freely, with no government control.
Last month, Prime Minister Ali Zaidan was kidnapped by a militia in the capital and released a few hours later by another militia.
Tensions were running high in Tripoli on Friday night and many Libyans were concerned that the violence could be the start of further unrest after grieving families bury their dead on Saturday.
"The cycle of violence has hit a peak tonight with tens dead and hundreds injured. As long as militias and armed groups are not held to account for crimes they commit, innocent people will continue to die," Human Rights Watch's Salah told CNN. "The government has a responsibility here to bring the perpetrators of these crimes to justice and hold them accountable for their acts."