Forces loyal to Muammar Qaddafi recaptured Zawiyah yesterday, residents said, after a fierce attack on what had been the rebel-held city closest to Tripoli.
Libyan state television showed footage of Col Qaddafi's supporters waving flags in what it said was a celebratory march in Zawiyah and a rebel fighter told Reuters that pro-Qaddafi forces had driven rebels from their stronghold in the central square.
A Sky News correspondent in Zawiya showed rebel-controlled tanks and vehicles mounted with machine guns, in the city's main square, and said pro-Qaddafi forces at the city's edge were fire constantly at moving vehicles, including ambulances.
Forces loyal to the Libyan leader have been fighting rebels in the east as well as in a handful of towns close to Tripoli, where he has total control.
A doctor confirmed the Reuters report and said the death toll in the day's fighting was at least 40 and probably many more.
"We have pulled back and they are inside the square but we will attack them again and have it back," the rebel fighter said in a telephone conversation.
"We will do that tonight. This is not the end."
The doctor said many dead lay in the streets, including old people, women and children. Al Jazeera television said several members of Colonel Qaddafi's forces were also killed, including a general and a colonel.
The counter-offensive by Colonel Qaddafi, almost three weeks after an uprising began against him in eastern Libya, has halted the rebels' advance in the east and left other rebels stranded in Zawiyah and another western city, Misrata.
A high-ranking member of the Libyan military flew to Cairo yesterday with a message for Egyptian army officials from Colonel Qaddafi. In Cairo, a Egyptian army official told the Associated Press that Maj. Gen Abdul-Rahman bin Ali al-Saiid al-Zawi, the head of Libya's logistics and supply authority, was asking to meet Egypt's military rulers.
There have been no public contacts between the Libyan regime and Egypt's generals since the Libyan uprising began on February 15.
At the same time, the Libyan government appeared to be putting out feelers towards western governments which have tried to isolate Col Qaddafi.
Libyan government emissaries appeared to have flown to Brussels to talk to European Union and Nato officials meeting today and tomorrow, Italian Foreign Minister Franco Frattini said, suggesting that the whole situation was very fluid.
Portugal's foreign minister was expected to meet another government official from Tripoli, the Lusa news agency said.
Meanwhile rebels in the east faced a fresh barrage of artillery fire on their desert front line outside the oil port of Ras Lanuf.
Dr Gebril Hewadi of the Benghazi medical management committee told Reuters television at least 400 people had been killed in eastern Libya since clashes began there on February 17, with many corpses yet to be recovered from bombing sites.
The eastern rebels renewed an appeal for outside powers to impose a no-fly zone to at least shield them from air attacks.
The US secretary of state, Hillary Clinton, made it clear imposing a no-fly zone is a matter for the United Nations and should not be a US-led initiative.
The White House said, however, it believed a UN arms embargo on Libya contained the flexibility to allow the rebels to be armed if such a decision were made.
Col Qaddafi's successes have left Western powers struggling to come up with a plan to support the rebels without becoming ensnared in the conflict.
US President Barack Obama's advisers were meeting yesterday to outline what steps are realistic and possible to pressure Col Qaddafi to halt the violence and give up power.
They planned to examine the ramifications of a no-fly zone over Libya and other military options, US officials said, speaking on condition of anonymity.
Britain and France are pushing for the UN to create a no-fly zone over the country, but there would be political difficulties.