* Bani Walid elders reject interference from NTC rulers
* Town was one of main pro-Gaddafi bastions during war
* Pro-government militia forced to flee in heavy fighting
* Clashes underline government's fragile hold on Libya
By Oliver Holmes
BANI WALID, Libya, Jan 24 (Reuters) - Libya's ramshackle government lost control of a former stronghold of Muammar Gaddafi on Tuesday after local people staged an armed uprising, posing the gravest challenge yet to the country's new rulers.
Elders in Bani Walid, where militias loyal to the ruling National Transitional Council (NTC) were driven out in a gunbattle a day earlier, said they were appointing their own local government and rejected any interference from the authorities in the capital Tripoli.
The town's revolt will heighten doubts in the West about the NTC government's ability to instil law and order crucial to rebuilding oil exports, to disarm tribal militias and guard Libyan borders in a region where al Qaeda is active.
Local elders denied reports that they were loyal to Gaddafi, who was captured and killed in October after weeks on the run, and Reuters reporters in Bani Walid saw no signs of the Gaddafi-era green flags which witnesses earlier said had been hoisted over the town.
But the collapse of NTC authority in the town, one of the most die-hard bastions of pro-Gaddafi sentiment during Libya's nine-month civil war last year, will compound the problems besetting a government that in the past week has been staggering from one crisis to another.
The uprising in Bani Walid could not come at a worse time for the National Transitional Council government. In the past week its chief has had his office overrun by protesters angry at the slow pace of reform and the second most senior official has quit, citing what he described as an "atmosphere of hatred."
Reuters reporters who entered Bani Walid on Tuesday morning saw a few of the black, green and red flags of last year's anti-Gaddafi rebellion but there was no sign of any central government presence.
About 200 elders who gathered in a mosque decided to abolish an NTC-appointed military council for the town and appoint their own local council, in direct defiance of the authority of the government in Tripoli.
"If (NTC chief Mustafa) Abdel Jalil is going to force anyone on us, we won't accept that by any means," one of the elders, Ali Zargoun, told Reuters at the mosque.
Accounts from Bani Walid, a town about 200 km (120 miles) from Tripoli, late on Monday described armed Gaddafi supporters attacking the barracks of the pro-government militia in the town and then forcing them to retreat.
A fighter with the routed pro-government militia told Reuters the loyalists were flying "brand new green flags" from the centre of town. The flags were symbols of Gaddafi's maverick, 42-year dictatorship.
But elders on Tuesday disputed that account.
"In the Libyan revolution, we have all become brothers. We will not be an obstacle to progress," said another elder, Miftah Jubarra. "Regarding allegations of pro-Gaddafi elements in Bani Walid, this is not true. This is the media. You will go around the city and find no green flags or pictures of Gaddafi."
Bani Walid, base of the powerful Warfallah tribe, was one of the last towns to surrender to the anti-Gaddafi rebellion last year.
A Libyan air official said war planes were being mobilised to fly to Bani Walid. But it was not immediately clear what the government in Tripoli could do. It has yet to demonstrate that it has an effective fighting force under its command and Bani Walid, protected behind a deep valley, is difficult to attack.
During Libya's nine-month war, anti-Gaddafi NTC rebels tried to take Bani Walid but did not progress much beyond the outskirts of the town. It later emerged that Saif al-Islam, one of Muammar Gaddafi's sons who was captured in the Sahara desert in November, had been using Bani Walid as a base.
Soon before the end of the conflict, with Gaddafi's defeat unavoidable, local tribal elders negotiated an agreement under which forces loyal to the NTC were able to enter the town without a fight.
Relations have been uneasy since then and there have been occasional flare-ups of violence.
A local resident, who did not want to be identified, said Monday's violence began when members of the May 28 militia, affiliated to the NTC, arrested some former Gaddafi loyalists. That prompted other supporters of the former leader to attack the militia's garrison. "They massacred men at the doors of the militia headquarters," said the resident.
The NTC still has the backing of the NATO powers who, with their diplomatic pressure and bombing campaign, helped push out Gaddafi and install the new government.
NTC authorities pledged to unify the tribally-divided country, reconstruct its once mighty oil industry that made Libya a major exporter in OPEC, and hold democratic elections.
But questions are now being raised inside some Western governments about the NTC's ability to govern Libya effectively and secure its frontiers against al Qaeda, arms traffickers and illegal migrants trying to get into Europe.
The NTC tumbled into its worst crisis since the end of the civil war at the weekend when a crowd of protesters in the eastern city of Benghazi stormed the council's local headquarters when NTC chief Mustafa Abdel Jalil was inside.
The protesters, who supported the revolt against Gaddafi, were angry that more progress had not been made to restore basic public services. They also said many of the NTC's members were tarnished by having served in Gaddafi's administration.
Abdel Hafiz Ghoga, deputy head of the NTC and target of some of the protests, said he was resigning. Abdel Jalil warned that the protests could drag the country into a "bottomless pit."
Additional reporting by Ali Shuaib; Writing by Christian Lowe; Editing by Mark Heinrich; Editing by Samia Nakhoul