* Tuareg rebels accept ceasefire deal
* AU chairman and UN envoy visit Kidal negotiate ceasefire
* Residents flee south in fear of renewed fighting (Recast with ceasefire deal reached, quotes)
By Tiemoko Diallo
BAMAKO, May 23 (Reuters) - Tuareg separatist groups in Mali on Friday accepted a ceasefire agreement with the government following clashes this week that threatened to plunged the country back into war.
The agreement was reached following a meeting between the chairman of the African Union and separatist groups in northern Mali to discuss a permanent truce and the resumption of talks between the rebels and the government in Bamako.
Mauritanian President Mohamed Ould Abdel Aziz and United Nations special representative in Mali Albert Koenders held talks for more than four hours with the three main rebel groups and local Tuareg traditional leaders in an effort to also revive peace negotiations between the two sides.
"I can confirm that we have agreed to a ceasefire," senior Tuareg official Ambeiry Ag Rhissa told Reuters by telephone from Kidal, the separatist stronghold.
"We have also agreed an exchange of prisoners and that an independent commission of inquiry should investigate what happened in Kidal."
The Malian army launched an assault on Kidal on Wednesday after clashes broke out last weekend during a visit to the northern town by new Prime Minister Moussa Mara. The action threatened to sink struggling the peace negotiations between the government and the rebels.
Mahamadou Camara, Mali's communication minister, said on Friday that President Ibrahim Boubacar Keita did not give the order for the army's failed attempt to retake Kidal. The government has launched an inquiry into the matter.
"We had accepted a ceasefire," Camara told Reuters. "Our forces decided on their own to go. They did not wait for the political order that should come down from the president to the prime minister and then the minister."
Defence minister Soumeylou Boubeye Maiga said late on Thursday about 20 soldiers had been killed and 30 others wounded in the failed attempt by government forces to retake Kidal.
The government has accused the separatists, including the National Movement for the Liberation of Azawad (MNLA), of renewing their former alliances with al Qaeda-linked Islamist groups.
"The MNLA was supported by its traditional allies," Maiga said.
Mali was plunged into chaos in 2012 after Tuareg independence fighters teamed up with armed Islamist groups to seize the north following a coup in the capital.
When they were sidelined by the better-equipped Islamists, the separatists broke with their allies. A French-led military operation drove the Islamists back last year.
The MNLA says it controls at least seven northern towns in addition to Kidal and that government troops either abandoned their positions and sought refuge at the camps of the U.N. peacekeeping mission MINUSMA or fled south on Wednesday.
Neither the U.N. nor French forces in Mali intervened to halt this week's clashes.
Fear of renewed fighting has pushed some people in Kidal, Gao and Timbuktu to seek refuge in the south, residents said.
"Many people have fled the city, especially state officials. All local administrators and regional directors of public services, including bank managers have all fled. Banks are closed in Timbuktu," said Ada Cissé, a local councillor in Salam near Timbuktu.
(Additional reporting by Adama Diarra in Bamako, Bate Felix in Dakar, Laurent Prieur in Nouakchott, Abdoulaye Massalaki in Niamey; Writing by Joe Bavier and Bate Felix; Editing by Angus MacSwan)