Libyan forces loyal to leader Muammar Gadafy fought their way into a town near the capital that has for days defied his rule, killing a rebel commander and pinning fighters into pockets of resistance.
At least 30 civilians were killed in the clashes, residents said by telephone.
An improvised force of rebels had been pushed back to the central Martyrs Square in Zawiyah, about 50 km west of the capital Tripoli, a rebel spokesman said.
"Now it's quiet. The number of dead people, nobody can say, they took away the bodies," rebel spokesman Youssef said by phone.
"One doctor told me they were shooting inside the hospital. Government troops are all around the city. I just came back from the square, our people are still there."
Mr Shagan earlier said many people had been killed in the small town of Harsha, just otuside Zawiyah, including rebel commander Hussein Darbruk. "We have appointed a new one."
A Libyan government official said: "It's been liberated, maybe there are still some pockets (under rebel control) but otherwise it's been liberated."
Deputy foreign minister Khaled Kaim said Zawiyah was in government hands, adding one rebel was killed.
"Zawiyah is back to normal today. According to some security sources, those who did not surrender have escaped. Locals are trying to catch them," he said.
"The situation is normal, the situation is under control. I hope this will be the case in other regions in coming days."
Earlier, Libyan government spokesman Mussa Ibrahim said forces hoped to regain control of Zawiyah "possibly tonight", adding negotiations were underway with Zawiyah rebel commanders to lay down their weapons and surrender.
Mr Shagan said government troops had surrounded the city and offered negotiations. "We will not talk to them, they have blood on their hands," he said.
Residents said dozens of people were killed in the fighting.
"We have counted 30 dead civilians. The hospital was full. They could not find space for the casualties," resident Mohamed said.
"We receive updates from the hospital and they say the number of casualties is rising," he added. Resident Ibrahim said between 40 and 50 people were killed in the clashes.
Mohamed said the pro-Gadafy forces used grenade-launchers, heavy machine guns and snipers on the rooftop of a new hotel in the town to fire at protesters while they marched after Friday prayers to demand the fall of the regime.
"People used swords and hunting rifles to defend Martyrs Square. Even mothers used those weapons," he added.
Ibrahim said: "People want martyrdom. There were children out protesting".
Their accounts could not be independently verified.
The rebellion in Zawiyah - the closest rebel-held territory to the capital and also the site of an oil refinery -- has been an embarrassment to the Libyan authorities who are trying to show they control at least the west of the country.
Eastern regions of the country, around the city of Benghazi, have already spun out of Gadafy's control after a popular revolt against his four decades of rule.
Earlier this week, people threw stones at posters of Gadafy in the square - which rebels re-named Martyr's Square in honour of those killed in the fighting that expelled government forces.
They showed off a captured armoury of tanks, armoured personnel carriers and anti-aircraft guns mounted on pick-up trucks. But the town was still encircled by large numbers of government troops and the rebels had been preparing for a major counter-attack.
"It's incredible. We can't let Gadafy continue massacring his own people," Ibrahim said. "We have no choice but to continue our fight against this dictator".