Friday's attack in the historic Malian city of Timbuktu began with the detonation of a car bomb at the military post.
A group of about 20 suspected jihadis then struck the nearby United Nations peacekeepers' compound, which is run mainly by Nigerian troops who are part of the UN's Multidimensional Integrated Stabilization Mission (MINUSMA).
The assailants seemed to have "really prepared their plan," a local resident told the AFP news agency.
"I believe that they first blew up their car so that MINUSMA forces would come out to inspect the damage, in order to attack them again," he said.
Attackers driven back
A Malian military source told AFP at least four suspected jihadis and a Malian soldier died during the assault in the northern city.
"At least four terrorists were killed, of whom two blew themselves up in their vehicle (and) three Malian soldiers were wounded and one killed."
UN spokesman Olivier Salgado said helicopters were used to repel the attack, and clashes later took place around a large former hotel located between central Timbuktu and the city's airport.
The city threatened
During the hours of fighting that ensued, reports suggested a vehicle being used by the assailants had "infiltrated the town of Timbuktu itself," the military source added.
Tuareg-led rebels and militant groups linked to al Qaeda took control of most of northern Mali in 2012.
Swathes of the country remain lawless despite a French-led military operation, which largely ousted the Islamists a year later, and led to a 2015 ceasefire with some rebel groups.
Gauck due in Mali
The attack came a week before German President Joachim Gauck was due to visit his country's troops stationed in Mali.
Germany's parliament recently approved a significant expansion of its military contribution to the UN peacekeeping operation, deploying an additional 650 soldiers.
The decision was prompted by a siege at a luxury hotel in the Malian capital Bamako in November, where Islamist militants took 170 hostages and killed 20 of them.
The country remains in a state of emergency amid fears of more terror attacks.
mm/sms (AFP, dpa)