imageBAMAKO: Armed rebels who humiliated Mali's army in a deadly offensive across the northern desert agreed to a ceasefire on Friday after talks with African Union chairman Mohamed Ould Abdel Aziz, a diplomatic source said.

Abdel Aziz “just obtained a ceasefire here in Kidal from representatives of the three armed groups he was meeting. Through this ceasefire, the groups undertake to stop fighting and stay where they are," the source told AFP by telephone from Kidal.

The source could not immediately provide any further details on the negotiations but said Abdel Aziz, the Mauritanian president, would leave “any time now".

Around 20 Malian soldiers have been killed and 30 wounded since Wednesday as Tuareg and Arab insurgents captured the flashpoint northern town of Kidal and the smaller settlement of Menaka, according to the defence ministry.

Abdel Aziz cut short a visit to Rwanda to hold urgent ceasefire talks with the National Movement for the Liberation of Azawad (MNLA), the High Council for the Unity of Azawad (HCUC) and the Arab Movement of Azawad (MAA).

He travelled by private jet and then helicopter to Kidal, 1,500 kilometres (900 miles) northeast of Bamako, accompanied by Bert Koenders, the head of MINUSMA, the UN mission in Mali.

Defence Minister Soumeylou Boubeye Maiga told AFP: “I wrote an official letter to MINUSMA today to confirm that the Malian army would respect the ceasefire."

The army has been pinned back since Saturday by a coalition of several armed groups, including Tuareg separatists.

The MNLA says 40 Malian soldiers have been killed and 70 taken prisoner since hostilities began on Saturday, with dozens of vehicles seized along with several tonnes of weapons and ammunition.

Fear of attack:

The diplomat in Kidal added that the Mauritanian president secured agreement from the armed groups for a resumption of peace talks with Bamako and the creation of an international investigation into the unrest that has rocked the north.

The latest fighting began outside the regional governor's office in Kidal on Saturday, coinciding with a trip to the town by Prime Minister Moussa Mara.

Rebels exchanged fire with Malian troops before kidnapping more than 30 civil servants, holding them for 48 hours before letting them go.

The town is the cradle of Mali's Tuareg separatist movement, which wants independence for a vast swathe of northern desert it calls “Azawad" and which has launched several rebellions since the 1960s.

The UN's High Commissioner for Refugees said on Friday that “small but growing numbers of people" were fleeing southwards, with some heading to Niger, Burkina Faso and other neighbouring countries.

“Our partner in northern Mali estimates that Kidal town has so far seen 3,000 people fleeing affected neighbourhoods," a UNHCR spokesman said in Geneva.

Edwards said buses for Bamako were “packed with people worried that the city might be attacked".

'Command chain failure':

Inhabitants of Kidal and Menaka, a town 300 kilometres (185 miles) to the south, told AFP there had been no fresh outbreak of fighting on Friday morning.

“On the ground, it's quiet. Aside from these two localities, armed groups don't have any real hold on any other position. The Malian army is in strategic locations like Almoustarat and Anefis," a foreign military source based in the north told AFP.

Meanwhile government officials said strategic errors were to blame for the army's defeat in Kidal.

“There was a big failure in the chain of command. It is clear that someone in the army took an initiative that was not theirs to take," a senior official told AFP.

The MNLA ended a nine-month occupation of the governor's offices in November last year as one of the conditions of a June peace deal that paved the way for presidential elections.

But the process deeply divided the MNLA, whose ultimate goal is the independence of Azawad.

Up until the agreement, the Tuareg group had refused to allow any government soldiers or civil servants into Kidal.

The country descended into crisis in January 2012, when the MNLA launched the latest in a string of Tuareg insurgencies in the north.

A subsequent coup in Bamako led to chaos, and militants linked to Al-Qaeda overpowered the Tuareg to seize control of Mali's northern desert.

A French-led military operation launched in January 2013 ousted the extremists, but sporadic attacks have continued, and the Tuareg demand for autonomy has not been resolved.