Libya's government has declared that it had taken control of one of the last strongholds of deposed leader Muammar Gaddafi's loyalists.
The declaration was followed by celebratory gunfire, with fighters in the heart of the city firing their guns into the air after fierce battles that left dozens dead and thousands displaced.
The capture of Bani Walid on Wednesday, some 140km southeast of the capital Tripoli, has been claimed as a triumph for the government that replaced Gaddafi's regime.
But the length of time it took the government to secure the town - a full year - underlined the difficulties faced by the new regime in imposing its authority over squabbling tribes and heavily armed militias.
Youssef al-Mankoush, the Libyan army chief of staff, said military operations in the city were terminated but that some forces were still chasing a few pockets of Gaddafi loyalists.
Al-Mankoush said the clashes resulted in a number of casualties, injuries and some were even kidnapped and held for a long time against their will.
Al Jazeera's Omar al-Saleh, reporting from Bani Walid, said: "Fighters tell me the situation inside the town remains tense."
"They are trying to clear pockets of resistance and there are few snipers positioned at different buildings," he said.
Nasser al-Manei, a government spokesman, said 50 people on the government side were killed and hundreds others wounded in the Bani Walid operation.
Speaking in Tripoli, al-Manei said about 100 of those wanted by the government were arrested, while 13 civilians held by the fighters in Bani Walid were freed.
Fear of violence
The victory could spark new violence, analysts say.
The government-backed militia that led the charge came from the city of Misrata, a longtime rival of Bani Walid, and it is feared reprisals could result.
Human Rights Watch, a New York-based rights group, was critical of the attack and urged the government to protect residents from revenge assaults.
In the centre of Bani Walid, shops were closed and streets were deserted.
Mohammed al-Taib, a commander of a pro-government militia called Libya Shield, told the Associated Press news agency that while his forces control the town centre, there was still fighting going on elsewhere.
A commander from the Misrata militia said his forces would remain in the town to keep Gaddafi loyalists out.
Bani Walid became a bastion of Gaddafi loyalists during and after the eight-month civil war that led to his killing and the fall of his regime last year.
It was occupied by anti-Gaddafi rebels who negotiated an entry after the leader's October death, but fighters loyal to the ousted regime rose up and pushed them out in January.
The Libyan government's new offensive came in the aftermath of the kidnapping, torturing and killing last month of an anti-Gadhafi fighter allegedly by residents of the town.