Forces loyal to Libya's government took control of the former Qadfafi stronghold of Bani Walid on Wednesday, commanders said, but pockets of resistance on the outskirts were reported.
Thousands have fled bloodshed this month between rival militias in the isolated hilltop town that was one of the last to surrender to rebels who overthrew Muammar Qadhafi last year.
The violence in Bani Walid has highlighted continued disorder in the oil-producing North African Arab country.
Pro-government fighters shouted "Bani Walid is free!" on Wednesday as dozens of pick-up trucks mounted with weapons filled a roundabout and streets in the center of the town some 170 km (105 miles) south of the coastal capital Tripoli.
Bent on making their mark on a town they say still harbors many followers of the late Qadhafi, pro-government forces fired rocket-propelled guns and anti-aircraft weapons at empty buildings. Heavy gunfire thundered non-stop and smoke billowed over part of the town. Shooting also clattered further off.
The fighters cried "Allahu Akbar" (God is Great) and "Today Bani Walid is finished," honking their car horns and blasting patriotic music from their trucks.
"On this day — October 24 — Bani Walid is free. There are no more Qadhafi militias inside," Fathi Shahoud, a commander of the Libya Shield grouping of militias aligned with the Defense Ministry, told Reuters. "Now we control the city and we will stay to ensure safety."
Tarek Nouri Abu-Shabi, a 21-year-old member of the Free Libya militia, said: "The revolutionaries have been in control since yesterday. These are rebels from Misrata, Tripoli and from other places. There are still small pockets of fighting on the outskirts. We found weapons inside the town."
Pro-government forces moved in on Bani Walid this month after Omran Shaban, the former rebel fighter who found Qadhafi hiding in a drain pipe in Sirte two months after rebels took Tripoli, died after being in detention there for two months.
Forces answering to the defense and interior ministries set out to find those suspected of abducting and torturing Shaban before he was eventually released, and the national congress gave Bani Walid a deadline to hand them over.
But the swoop on Bani Walid drove home the Tripoli government's inability to reconcile groups with long-running grievances, as well as its failure to bring many of the militias that deposed Qadhafi fully under its control.
Twenty-two dead, thousands displaced
According to the Libyan state news agency, the clashes in Bani Walid have killed at least 22 people and injured hundreds. Thousands of families from Bani Walid fled the violence.
There were unconfirmed reports of retribution against Bani Walid residents by pro-government forces.
"The militias have entered the suburbs with bulldozers and have begun to demolish homes without reason," Abdel-Hamid Saleh, a member of a Bani Walid civil society group, said by phone on Tuesday. "A woman called me yesterday screaming, 'They have come for me, they have come for me' in fear.
"The city is falling on our heads."
Fleeing residents have said that there is no water or electricity inside the city and a shortage of food and medicine.
The Bani Walid General Hospital was evacuated earlier this week when, according to residents, it came under a rocket and mortar barrage. "The patients have been moved to hiding places, homes and mosques because they were under fire in the hospital," tribal elder Mohammed al-Shetwai told Reuters.
A Reuters team was unable to reach the hospital because of extensive shooting in Bani Walid on Wednesday.
The International Committee of the Red Cross said it had previously delivered surgical supplies to treat around 100 patients wounded by shooting inside the city, as well as other urgently needed medical supplies.
Fighters, young and old — some dressed in civilian clothes — climbed onto the roof of one building to hoist Libya's tricolor flag and then fired their rifles in the air.
Posters of Shabban as well as Misrata historical hero Ramadan al-Swehli hung atop one of central Bani Walid's buildings, next to an empty coffee shop where plastic chairs still stood outside.
A main street in the center of the town was empty except for the Libya Shield fighters. Just outside Bani Walid, fighters continued the celebration with gunfire.
On Saturday, Libyan congress leader Mohammed Magarief said that not all areas of the country had been fully "liberated," one year after the capture and killing of Qadhafi, which put a damper on Tripoli's anniversary celebrations on Tuesday.
Libya was declared liberated a few days after his death on 20 October 2011, and while its new rulers have led the nation to elections, they have struggled to impose their authority on a country full of military weapons in private hands.