By Cheik Amadou Diouara

BAMAKO (Reuters) - Up to 20 people were killed and at least 40 others wounded, according to health workers, in two days of fighting in northern Mali between Tuareg rebels and pro-government militia threatening a shaky year-old peace deal.

The Tuareg-dominated Coordination of Azawad Movements (CMA) and rival Gatia militia fighters, who had peacefully shared control of the town of Kidal since February, clashed for a second day on Friday before pro-government fighters withdrew.

Both groups signed a United Nations-backed deal a year ago with the government in Bamako, the capital in southern Mali, that was meant to end a decades-long cycle of uprisings and let the army focus on defeating jihadist groups in the desert north.

A nurse at the main health center in Kidal, one of the largest towns in northern Mali, said she had seen about 20 dead, both at the clinic and on the town's streets.

"There are wounded people everywhere. Forty wounded, with four bad cases. One of them was shot in the throat, another in the back, another in the abdomen," a doctor at the health center told Reuters by telephone, asking not to be named.

Red Cross volunteer Ahamed Ag Mohomedine said he had counted over 15 bodies, adding many wounded had been taken to the Kidal base of Mali's U.N. peacekeeping mission MINUSMA.

Both armed groups gave death tolls from the fighting that were lopsided in their own favor and could not be independently verified.

Mali's government, which has not had a military presence in Kidal since clashes between the army and Tuareg rebels killed 50 soldiers there in 2014, urged both sides to end the fighting.

"The government of the Republic of Mali considers that the situation created by these clashes constitutes a serious threat to the implementation of the peace accord," it said in a statement.

MINUSMA said it had stationed troops in heavily populated areas to protect civilians.

The U.N. also deployed drones to monitor the fighting, and a regionwide French counter-terrorism mission used helicopters to patrol the skies above the town, said MINUSMA spokeswoman Radhia Achouri.

"Our main concern is that civilians are in the line of fire," she said, adding that some town residents had taken shelter inside the MINUSMA camp overnight.

The gunfire had largely subsided by mid-afternoon on Friday, as the CMA claimed to have driven Gatia fighters from Kidal, a traditional stronghold of the Tuareg separatist movement.

"We control the town in its entirety along with the surrounding areas. Calm has returned," said CMA spokesman Almou Ag Mohamed.

Two officers in the pro-government militia confirmed that Gatia had withdrawn from the town.

"We decided to draw back from Kidal, but we are in the process of reorganizing," one of the officers said, asking that his name not be used for his protection.

The U.N. called for an immediate cessation of hostilities and said that it is working with leaders of both groups to mediate the conflict and resume the peace process.

(Additional reporting by Tiemoko Diallo; Writing by Nellie Peyton and Joe Bavier; Editing by Tom Heneghan)