Libya's government declared Wednesday that it had taken control of one of the last strongholds of deposed dictator Moammar Gadhafi's loyalists, as its fighters in the heart of the city fired their guns into the air to celebrate victory after fierce battles that left dozens dead and thousands displaced.

The capture of Bani Walid, some 140 kilometers (90 miles) southeast of Tripoli, was a triumph for the government that replaced Gadhafi'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.

The victory could even spark new violence. The government-backed militia that led the charge came from the city of Misrata, a longtime rival of Bani Walid, and reprisals could result.

The New York based Human Rights Watch group was critical of the attack and urged the government to protect residents from revenge attacks.

The Libyan military's Chief of Staff Youssef al-Mankoush said military operations in the city were terminated but that some forces were still chasing a few pockets of Gadhafi loyalists. He was speaking in Tripoli.

In the center of Bani Walid, shops were closed and streets were deserted. A power station was destroyed, the main hospital was not functioning and a doctor was among the wounded. Fighters opened fire on street signs that bore language associated with Gadhafi's regime, such the name he gave to the country. A portrait of the slain dictator had its face punched out with bullet holes.

"Bani Walid is under full control," the official LANA news agency quoted the spokesman of the pro-government militia, Mohammed al-Kandouz, as saying late Tuesday.

But Mohammed al-Taib, a commander of a pro-government militia called Libya Shield, told The Associated Press that while his forces control the town center, there was still fighting going on elsewhere. Columns of smoke billowed near the airport where militiamen said they were meeting resistance.

Omar Boughdad, a commander from the Misrata militia, said his forces would remain in the town to keep Gadhafi loyalists out. "The loyalists have fled to the valleys, but we will clean up these places and we will not leave again," he said.

Bani Walid became a bastion of Gadhafi loyalists during and after the eight-month civil war that led to Gadhafi's killing and the fall of his regime last year.

It was occupied by anti-Gadhafi 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.

The country's newly elected General National Congress issued a decree to arrest the men accused of the killing. Efforts for a peaceful resolution through negotiations with the town's elders failed.

Government spokesman Nasser al-Manei said 50 people on the government side were killed and hundreds others wounded in the Bani Walid operation. Al-Manei, speaking in Tripoli, said about 100 of those wanted by the government were arrested, while 13 civilians held by the fighters in Bani Walid were freed.

The government had no figures for casualties among the defenders.

Human Rights Watch said in a statement Wednesday it was not clear how many died in the fighting. Doctors said at least seven civilians were killed in the monthlong conflict. The group had figures until Oct. 18, before the final push on the town.

The group urged the government to protect the residents from revenge attacks and criticized the assault on the town.

"The need to arrest criminal suspects should not have led to a military assault on Bani Walid," said Fred Abrahams of Human Rights Watch. "Now the government needs to do everything it can to protect the town's residents from retribution and help them rebuild their lives."

Mohammed al-Harari, minister of local administration, said that 10,300 families were displaced by the fighting. It was not clear how many individuals this figure comprised.

Interim President Mohammed El-Megarif expressed support for the offensive on Bani Walid in a speech aired on national TV. "This is not targeting a region, a tribe or unarmed civilians, but outlaws," he said. "This is to impose state legitimacy."