Forces loyal to Moammar Gaddafi stormed this rebel stronghold Saturday for the first time since coalition airstrikes began last month, moving the front line closer to the opposition capital, Benghazi.

Gaddafi loyalists approached Ajdabiya from the south and from the coast, and fierce street battles erupted in the heart of the city, 100 miles south of Benghazi. The loyalists also pummeled the western gate to Ajdabiya with mortar shells and artillery rounds for a third straight day.

Some rebels fled the city during the afternoon. But by nightfall, opposition forces said they had pushed most of the loyalists out of town and captured at least three, including a high-ranking officer. Sporadic street fighting continued into the night.

But the battle showed that the ragtag rebel army of the east remains in disarray as Gaddafi’s forces gain ground and adapt to NATO airstrikes. Since NATO took control of the skies from coalition forces — who struck last month to stop Gaddafi’s forces from overrunning the east — the front line has crept slowly toward Benghazi, where the uprising against Gaddafi began in February.

NATO said in a statement Saturday that it had struck key ammunition sites and armored vehicles belonging to Gaddafi’s forces. The statement warned that if the Libyan leader’s troops continued to kill and target their own people, NATO would attack.

“We have observed horrific examples of Regime forces deliberately placing their weapons systems close to civilians, their homes and even their places of worship,” Lt. Gen. Charlie Bouchard, commander of NATO’s Libya operation, said in a statement. “Troops have also been observed hiding behind women and children. This type of behavior violates the principles of international law and will not be tolerated.”

Opposition forces have criticized NATO after airstrikes twice hit rebel fighters as well as for allowing Gaddafi’s forces to advance.

The rebels say the fight has become more difficult because the loyalist forces are driving civilian cars and have begun to dress like rebels.

Salah Awad Ali, a teacher and rebel fighter who has darted in and out of the city, said he could no longer tell who was fighting with him and who was fighting with Gaddafi. “We don’t know who is who,” he said. “Only the sons of Ajdabiya can fight now. They know the strangers.”

Outside Ajdabiya, the rebels blamed one another for the breach Saturday.

“All the Benghazi people keep running away when Gaddafi forces attack,” Mohammed el-Fakhry, a resident of Benghazi, said after he had prayed.

Fakhry had traveled to Ajdabiya to pick up the body of his cousin, who was killed in the battle Saturday. Men prayed over the body, which was in an open coffin on the back of a truck, and then drove it east to the young man’s father in Benghazi.

Nearby, a group of men pushed and shoved one another, arguing about who had fled and who had stayed to fight.

“The people of Ajdabiya are the only ones who will defend their city. Everyone else runs,” an older man yelled.

Col. Ahmed Bani, a spokesman for the opposition army, said the rebels had lured Gaddafi loyalists into the city and ambushed them so that the rebels could secure their ground both here and in the strategic oil hub of Brega.

“Ajdabiya was like cheese for the rats,” Bani said. “We attacked them and defeated them. It was a trick of war.”

But it was clear Saturday that the opposition forces had been taken by surprise. And despite claims that they had seized control of Brega, fighters and residents of that city said the rebels were pushed back by artillery and missile fire.

Abdul Karim Mohammed stood on the outskirts of Ajdabiya on Saturday afternoon. He had tried to return to his home in Brega but was stopped by machine-gun fire around him, so he retreated to the western gate,

He continued to retreat as rockets hit the center of the city.

Today would not be the day he returned home.