At least eight people were killed in the fighting over Ajdabiya, a hospital official said.
Recapturing the city would give the Libyan military a staging ground to attack the rebels' main stronghold, Benghazi, about 100 miles (160 kilometers) farther east along the coastal highway. Moammar Gadhafi's forces were approaching Benghazi when they were driven back by the international air campaign launched last month to protect civilians and ground Gadhafi's aircraft.
For the rebels, losing the city would effectively bottle them into a coastal strip of eastern Libya and allow government forces to more tightly squeeze the few opposition pockets in the rest of the country, including the besieged western port of Misrata, where heavy clashes continued Saturday for a second day.
NATO airstrikes hit armored vehicles firing on civilians near both Misrata and Ajdabiya, said Canadian Lt. Gen. Charles Bouchard, who commands the Libya operation.
Speaking in Naples, Italy, where the alliance's operational center is located, Bouchard said Saturday that NATO jets also had struck ammunition stockpiles east of Tripoli that were being used to resupply forces involved in the shelling of Misrata and other population centers.
A NATO official who spoke on condition of anonymity because of regulations said warplanes had destroyed 17 tanks and damaged nine more. The official also said NATO jets enforcing the no-fly zone over Libya intercepted a rebel Mig-23 fighter that had taken off from Benghazi and forced it back to the airport. No shots were fired, the official said.
International envoys opened fresh initiatives for a peace deal. The African Union said it planned to send a team to Libya on Sunday to begin meetings with the government and rebel leaders.
In the capital Tripoli, meanwhile, Gadhafi made his first public appearance in weeks with a visit to a school. Children jumped on desks and gave fist-pumping chants: "The people want Moammar the leader!"
Wearing large black sunglasses and a brown turban and robe, Gadhafi made no public comments, according to the account on state TV. Gadhafi has remained mostly in hiding since the airstrikes began, preferring to communicate by telephone to government-run television.
The battle for Ajdabiya showed how Gadhafi's forces are adapting their strategies amid NATO airstrikes seeking to cripple the Libyan military.
Small and mobile units -- less vulnerable to airstrikes than tanks and other armor -- first ambushed a rebel convoy probing the lines outside the city. Government gunners then began shelling Ajdabiya from desert positions and later ferried soldiers into the streets using civilian vehicles in attempts to foil NATO pilots.
A possible NATO airstrike, kicking up a huge mushroom cloud, temporarily halted the shelling. NATO officials did not immediately confirm an attack.
A helicopter gunship -- possibly a rebel aircraft coming from the direction of Benghazi -- passed over the city during the fighting.
By nightfall, heavy gunfire was heard from apparent block-to-block combat inside the city, which had about 150,000 residents before many fled for safer areas.
A resident leaving the city, Abdul Fatah, said gun battles raged along the city's main street. A rebel fighter, Salah Ali, said Gadhafi's forces were "spreading out inside Ajdabiya" with weapons including heavy machine guns and grenade launchers.
The supervisor at Ajdabiya hospital, Mohammed Idris, said at least eight rebels were killed and nine people were injured, including two civilians.
The rebels have maintained control of much of the eastern half of Libya since early in the uprising, while Gadhafi has clung to much of the west. Gadhafi has been putting out feelers for a cease-fire but he refuses to step down as rebels demand.
The NATO-led airstrikes, authorized by a U.N. resolution, have neutralized Gadhafi's air force and pummeled his ground forces, but the opposition remains outnumbered and outgunned. The alliance has been defending itself against rebel complaints that its attacks are too slow and imprecise.
In Misrata, rebels and government troops have battled since Friday for control of a key roadway linking the port -- a lifeline for opposition fighters and trapped civilians. A doctor who spoke to The Associated Press by phone said at least seven people had been killed.
The doctor spoke on condition of anonymity because of fear of reprisals. The accounts could not be independently verified because Libyan authorities have blocked journalists from conducting their own reporting in the city.
For a second consecutive day, international journalists were taken on a government-supervised trip to the outskirts of Misrata. In a farming area south of the city, pro-Gadhafi forces manned positions with pickup trucks mounted with anti-aircraft guns. Tents and sniper nests were hidden in trees and brush.
Also in Misrata, the Red Cross said a relief ship reached the port. A Turkish ship also docked in Misrata to bring home Egyptians stranded in Libya's third-largest city, said Egypt's deputy foreign minister, Mohammed Abdel-Hakam. A second Turkish ship was expected Sunday.