Rival militias fought a two-hour gunbattle over a luxury beach house being used as a barracks in the Libyan capital on Wednesday, underscoring how volatile the country is following the overthrow of Muammar Gaddafi.

A Reuters reporter heard exchanges of both heavy and light weapons coming from the Tripoli district of El-Saadi beach, a stretch of Mediterranean coast overlooked by office skyscrapers and the Marriott Hotel.

Militias have carved up Tripoli and the rest of Libya into competing fiefdoms, each holding out for the share of power they say they are owed.

A witness, who had been relaxing on the beach with his family, told a local television channel fighters armed with anti-aircraft guns screeched along the coastal highway and stormed a walled residence.

It was chaos, the fighters suddenly arrived in cars and started shooting at the house. Families fled from the beach, Abdul Musharim told the Libyan news channel 'Libya'.

A militia from Misrata, that arrived in Tripoli during the civil war last year, had been using the house as a barracks. It used to be owned by Gaddafi's son Saadi, a businessman and former professional footballer who is in Niger after escaping across the border when National Transitional Council (NTC) forces captured Tripoli in August.

A member of the NTC's High Security Committee said the fighting was between militiamen from Misrata and units from Zintan. Both groups fought to oust Gaddafi.

We are not sure what the fighting was about but government forces have surrounded the area and it is calm now, the official said on condition of anonymity.

Black smoke rose from the beach house on Wednesday and armed men who said they were working for the Interior Ministry circled the building and warned journalists their cameras would be smashed if they did not leave the area.

The NTC is struggling to impose its authority on the country and form a functioning national police force and army.

There is nothing going on here, it is safe an irate man told Reuters as gunfire erupted behind him.

In the chaos, men could be seen running along the beach carrying crates of ammunition taken from the house.

Several militias from outside the capital have set up bases in Tripoli. They clash intermittently often because of disputes over who controls which neighbourhoods of the city.

The violence on Wednesday was the first time in weeks that a major gunbattle had broken out in the centre of the capital.

(Additional reporting by Ali Shuabi and Taha Zargoun; Editing by Janet Lawrence)