Libyan government forces captured the town of Bani Walid on Wednesday, ending an eight-day battle that has cost at least 20 lives and left more than 200 wounded.

The desert town, described by the government as Libya's last stronghold loyal to Muammar Gaddafi, has defied official control since January.

Government spokesman Nasser al-Mana'a said the offensive followed a string of kidnappings by gangs in the town and the murder of a former militiaman credited with capturing Gaddafi last year.

"Bani Walid had become a centre for fugitives from justice, kidnappers – we can say they kidnapped the city," he said.

Television pictures showed army units backed by pickup trucks carrying anti-aircraft guns being deployed in a town square in the centre. A uniformed pro-government militia commander, Feras Sewehli, said: "Bani Walid is under government control."

The president of Libya's parliament, Mohamed el-Magariaf, said human rights were being respected by army forces, after the UN secretary general, Ban Ki-moon called for all sides to show restraint. "Military operations in Bani Walid do not target the city and its people," Magariaf said.

The International Committee of the Red Cross reported that 25,000 of the town's estimated 80,000 population have fled to refugee camps outside town because of the fighting, the worst Libya has seen since the end of October 2011.

At the weekend, supporters of the rebels in Bani Walid mobs tried to storm the national parliament in Tripoli and wrecked a pro-government television station in Benghazi.

Unverified reports from inside the town said there had been massacres, indiscriminate shelling and a poison gas attack but no evidence has yet emerged.

Bani Walid's television station remained on air throughout the day, labelling army forces as "gangsters" and showing footage of two children, one dead from a head wound and the other missing a foot.

"We went in this morning and captured the town, now all is under control," said pro-government fighter Muhsen al-Gubbi. "We are being careful not to target civilians and not use rockets in civilian areas."

Earlier this month, the government ordered the army to use "all necessary means" to free the kidnapped and arrest criminals and Gaddafi-era officials.

Army leaders will be pleased with the control of units built around last year's rebel militias.

The offensive saw Misratan units outflank the main defensive positions of Bani Walid. But the reality is Libya remains deeply divided along tribal lines, with Bani Walid and other former pro-Gaddafi towns resisting the new order.