After a week of efforts to negotiate a peaceful surrender of Bani Walid — one of the last bastions of Gadhafi loyalists — anti-regime fighters launched a two-pronged assault on the town that soon dissolved into street fighting. But Gadhafi supporters have put up fierce resistance and forced former rebels to retreat Saturday amid a barrage of rocket and mortar fire.

Bani Walid is one of three significant remaining bastions of support for Col. Gadhafi, along with Sirte, the dictator’s hometown, on the Mediterranean coast and Sabha in the southern desert. The surprisingly stiff resistance has continued despite the effective end of Col. Gadhafi’s nearly 42-year rule on Aug. 21, when Libyan fighters swept into the capital, Tripoli.

After pulling back under heavy fire Saturday, Libyan fighters pushed back into Bani Walid on Sunday, fighter Sobhi Warfali said. Revolutionary forces now control the northern half of the town, he said, and are battling regime loyalists in the center.

Resident Khalifa al-Talisi said, “The rebels don’t control the center yet, but everything from the city center to this (northern) side is liberated.”

Around a mile from the town center, a cluster of abandoned houses in the desert showed signs of the fierce fighting there. The charred hulk of a car stood in front of a still-burning home that sent plumes of black smoke into the air.

Single gunshots, which appeared to be from snipers, occasionally echoed across the dusty town, and the thud of mortar fire shook the ground. Big plumes of black smoke could be seen wafting over the rooftops.

“The Gadhafi loyalists are throwing mortars, and snipers are shooting at us from the center of the city,” said Abdul-Bari al-Mitag, a 23-year-old fighter returning from the front line.

NATO, which has played a key role in hitting Col. Gadhafi’s forces over the six-month civil war, said Sunday that its warplanes had hit a series of targets near Bani Walid a day earlier — a tank, two armed vehicles and one multiple rocket launcher. Airstrikes also pounded targets around Sirte and the towns of Waddan and Sabha in the southern desert.

A military commander for former rebels near Bani Walid, Abdel-Razak al-Nadouri, said a sizable force pushed into the town on Saturday but met heavy resistance and NATO asked them to pull back to allow the airstrikes.

“A large number of people entered Bani Walid, but we had to retreat because of heavy fire,” he said. “Yesterday, NATO asked us to return seven kilometers (three miles) from Bani Walid because they were striking military bases and Grad rocket launchers.”

The former rebels launched the assault on Bani Walid after negotiations for the town’s surrender broke down Friday.

Libya’s new leaders also have been trying to broker a deal for the surrender of Sirte. But a deadline for the town’s surrender expired Saturday, and a revolutionary commander taking part in the negotiations, Mustafa al-Rubaie, said, “Now all options are open.”

Libyan fighters have advanced to within 20 miles west of Sirte and in the east as far as the town of Harawa, some 35 miles from the city, according to Mr. al-Rubaie.

He said fighters from Harawa will lead the force into Sirte “because they are from the city and they are part of the Sirte people.”

“I think it will not be a 100 percent peaceful takeover of Sirte. There will be pockets of loyalists,” he said. “In general, the people of Sirte are all armed with light weapons, even youngsters.”

Mr. Al-Rubaie said that over the past months Col. Gadhafi’s forces that fled from all the eastern cities and from Misrata are all now concentrating in Sirte.

“We know that they are not going to give up easily,” he said. “For them, it will be a matter of life or death.”