Libyan pro-government forces on Wednesday seized control of Bani Walid, one of the last bastions of Moamer Kadhafi's ousted regime, an AFP correspondent in the town said.
Hundreds of fighters, mostly former rebels from the rival town of Misrata, converged on the centre of Bani Walid, firing in the air to celebrate and hoisting the Libyan flag on abandoned public buildings, he said.
Some of the fighters blasted the walls and windows with anti-tank rockets and Kalashnikov rifles.
Several rebel chiefs, whose fighters patrolled in vehicles mounted with heavy weapons, told AFP the town was "almost liberated," with only a few pockets of resistance left in its southern sector.
Later in the day Libyan army chief-of-staff, Yussef al-Mangouch, officially announced the end of all military operations in the town, despite some pockets of resistance.
Mangouch told a news conference his troops were on a manhunt to track down several fighters who had fled towards the desert.
Warplanes were seen in the distance flying over the outskirts of the oasis town, itself deserted with residents and foreign workers having fled since Sunday.
Pro-government forces patrolled the ghost town in vehicles mounted with heavy machine guns.
Government spokesman Nasser al-Manaa said meanwhile that about 100 suspects were arrested in Bani Walid in connection with crimes committed during last year's revolution -- namely combatants who sided with Kadhafi forces.
Speaking at a news conference, Manaa also gave a death toll of 50 government forces killed and said hundreds were wounded in the battles with "well-trained combatants in Bani Walid who possessed modern weapons."
Local governance minister Mohamed al-Hrari also told reporters more than 10,000 families fled the fighting in Bani Walid to neighbouring towns, including Tarhuna.
Fierce clashes in Bani Walid, which was accused of harbouring die-hard Kadhafi loyalists, cast a pall over celebrations for the first anniversary this week of the overthrow of his regime in a bloody conflict.
The fighting fanned old tribal feuds and underscored the difficulties of achieving national reconciliation.
A scaled-up offensive against Bani Walid since last week came in response to the death of Omran Shaaban, 22, a former rebel from the city of Misrata who was credited with capturing Kadhafi.
Shaaban spent weeks held hostage in Bani Walid, where he was shot and allegedly tortured, before the authorities managed to broker his release.
He later died of injuries sustained during the ordeal, stoking tensions between his hometown Misrata and Bani Walid, long-time rivals which fought on opposite sides of the 2011 conflict, and galvanising the authorities to act.
The victorious fighters on Wednesday carried massive portraits of Shaaban and of Ramadan al-Swihli, a resistance hero who fought Italian colonial powers and was killed in 1920 in Bani Walid.
Clashes between pro-government forces and Bani Walid fighters over the past week killed dozens of people and wounded hundreds, in scenes evocative of the civil war that led to Kadhafi's overthrow and death.
Tribal leaders and commanders in Bani Walid, 185 kilometres (115 miles) southeast of Tripoli, had accused "lawless Misrata militias" of seeking to annihilate their historic rival.