Tripoli, Libya (CNN) -- A battle raged in a strategically located Libyan city Saturday as state television showed a fist-pumping Moammar Gadhafi visiting a school, his first public appearance in days.
Rebels fought hard in a back-and-forth war for Ajdabiya, the last stop before their stronghold, Benghazi, further to the east. Witnesses reported three hours of fighting that they said involved explosions caused by NATO aircraft.
As the sun set, the rebels appeared to have averted a major setback by maintaining control of the hard-won city -- but it was tenuous at best. Outgunned, they conceded they were facing a formidable foe.
In a hospital, witnesses told CNN that three of Gadhafi's fighters who were killed were carrying identification cards from Syria, Algeria and Chad.
NATO said in the past 24 hours its aircraft destroyed loyalist ammunition stockpiles east of Tripoli that were supplying troops shelling Misrata and other cities. Attacks also were made on armored vehicles near Misrata and Ajdabiya, it said.
Opposition spokesman Shamsiddin Abdulmolah told CNN that rebels flew two attack helicopters from Tobruk to join the fighting in Ajdabiya.
"There were some 50 regime pickup trucks with machine guns and rocket launchers that attempted to enter Ajdabiya," Abdulmolah said. "The helicopters destroyed several of the trucks and the rest took off."
Abdulmolah did not know what kind of helicopters the rebel forces used in Saturday's attack and could not confirm whether rebel forces coordinated the operation with NATO.
Far from the battleground, African leaders were meeting in Mauritania Saturday in an attempt to forge a mediator role in Libya's impasse.
The African Union's special committee on Libya -- represented by Mauritania, Congo Republic, Mali, Uganda and South Africa -- will then travel to the Libyan rebel stronghold of Benghazi to meet with the opposition leaders Sunday and Monday, according to the South African government.
The South African government also said NATO has granted the committee permission to meet with Gadhafi in the Libyan capital, Tripoli.
Gadhafi has been a big supporter of the African Union and has channeled large sums of money its way. Libya also holds a seat on the 15-member Peace and Security Council. As such, opposition leaders in Benghazi did not express optimism over the success of mediation.
The United Nations said Secretary-General Ban Ki-moon will travel to Cairo Thursday to head meetings on Libya at the Arab League headquarters. Among the participants will be Catherine Ashton, the representative for foreign affairs and security for the European Union.
Meanwhile, Libyan Foreign Minister Khaled Gaim condemned on state-run television the reopening of key ports in the eastern cities of Tobruk and Benghazi, which he said enables the rebels to resume an oil trade. He accused NATO of violating the United Nations Security Council resolution that mandates the protection of civilians.
State TV also aired images Gadhafi visiting on Saturday what appeared to be a primary school in Tripoli. The anchor said the school was a target of international airstrikes and was going to be attacked.
Former U.S. lawmaker Curt Weldon visited Libya this week hoping to speak directly with Gadhafi but left without a meeting. He did manage to secure a letter from the strongman to U.S. Secretary of State Hillary Clinton.
"I am disappointed that I did not get to sit down face to face with Colonel Gadhafi as promised, but I may have been able to get something even more significant -- a path to a resolution of this conflict," Weldon said in a statement on his departure.
Weldon visited Libya in 2004 when he was a Republican congressman from Pennsylvania and said he was invited this time by Gadhafi.
Peace efforts seemed distant Saturday in Ajdabiya, where Gadhafi's forces attacked with a barrage of artillery fire at the city's western gates. Street fighting erupted as the loyalists, aided by sympathizers, entered the city. At one point, opposition fighters appeared to have all but lost again territory that was hard won.
At the height of their march toward Tripoli, rebels came within 40 kilometers (25 miles) of Sirte -- Gadhafi's hometown in western Libya. But loyalist forces have steadily pushed the rebels back and now stand poised to run down the highway to Benghazi, the opposition's capital.
Burnt carcasses of Libyan army tanks taken out by coalition aircraft three weeks ago litter the road. But it's increasingly harder to distinguish pro-Gadhafi troops. They have changed tactics and have taken to moving about in civilian vehicles.
"The troops of Gadhafi have good weapons and have training and have leadership and have experience," one rebel fighter said.
CNN's Ben Wedeman, Reza Sayah and Nic Robertson contributed to this report