The key northern Mozambique town of Palma was all but deserted Monday, its residents fleeing by road, boat or on foot as the Islamic State (IS) group claimed control after a prolonged onslaught.
IS-linked militants attacked the town on Wednesday, escalating an insurgency that has spread bloodily across northern Mozambique since 2017.
Dozens of people, according to the IS and the authorities, were killed in what witnesses describe as a coordinated attack, and an unknown number were still missing.
It is the closest raid yet to a multi-billion-dollar gas project being built on a peninsula just 10 kilometres (six miles) away, by France's Total and other energy giants.
"The caliphate's soldiers seized the strategic town of Palma," IS said in a statement posted on its Telegram channels.
It claimed its offensive aimed at military and government targets, killing dozens of troops and "members of Crusader states," its term for Western nationals.
The town of 75,000 people in Cabo Delgado province was all but emptied of its population, said civil society activist Adriano Nuvunga.
"The violence has ceased, but it is believed some of the insurgents have pulled back and some are still around in hiding," he told AFP.
Witnesses said scores of fighters had sneaked into the town ahead of the attack.
"The attackers arrived a few days earlier and hid in the homes of locals whom they paid," said one Palma resident, speaking from Mueda, where he had taken refuge.
"The attacks started along the main roads to Palma," he said.
As police rushed out to try repel the invaders, the fighters inside the town mounted their own attack, according to witnesses.
The United Nations condemned the assault on Palma and said it was coordinating closely with local authorities to provide assistance to those affected by the violence.
"We are deeply concerned by the still evolving situation in Palma where armed attacks began on March 24, reportedly killing dozens of people," UN spokesman Stephane Dujarric said.
Many survivors said they had walked for days through forest to seek refuge in Mueda, 180 kilometres (112 miles) to the south, where they arrived limping on swollen feet.
"Many people fell from fatigue and were unable to continue walking, especially the elderly and children," said one escapee in Mueda who did not wish to be named.
Some survivors fled to the gas project site, from where they are being sent to the regional capital Pemba via boat.
The government said dozens were killed in the militants' attack, including seven people caught in an ambush during an operation to evacuate them from a hotel where they had sought refuge.
A South African is among those killed, his family said.
"Attacks started shortly after a large ship with food had just arrived," one escapee told AFP via an online message, referring to food aid deliveries to the farthest northern coastal town.
"They attacked the city and brought trucks to carry the food."
Witnesses told AFP they first targeted banks and the police station before spreading across town.
Thousands of escapees were arriving on boats on Monday in Pemba, the provincial capital around 250 kms to the south, according to sources there.
International aid agency sources said between 6,000 and 10,000 people were waiting to be evacuated.
The attack forced expatriate workers and locals to seek refuge temporarily at a heavily guarded gas plant located on the nearby Afungi peninsula.
"A significant number of civilians rescued from Palma are also being transported to Afungi site, where they receive humanitarian and logistical support," side Total in a statement.
Sea Star, a large passenger vessel, arrived in Pemba on Sunday with around 1,400 people, mostly workers including Total employees.
Pemba is already packed with hundreds of thousands of other people displaced by the Islamist insurgency, which has uprooted nearly 700,000 from their homes across the vast province.
The latest attack "will unleash a new onslaught of displaced people," said Chance Briggs of the British-based charity Save the Children.
The defence ministry said late Sunday the security forces had "reinforced their operational strategy" to contain the attacks and restore normality in Palma.
In Portugal, Prime Minister Antonio Costa said his government was monitoring the situation with "great concern," adding that he had been in touch with President Filipe Nyusi.
The violent, calculated raid broke a three-month hiatus in Islamist attacks widely attributed to counter-insurgency tactics and the January-March rainy season.
Although the extremists launched their campaign in 2017, experts say they began mobilising a decade earlier as disgruntled youths started to practise a stricter form of Islam, upset over locals drinking alcohol and entering mosques dressed in shorts and shoes.
Their bloody campaign has claimed at least 2,600 lives, half of them civilians.
The insurgents are known locally as al-Shabaaab, although they are not believed to have links with the Somali jihadist organisation by that name.
The US State Department this month said the group reportedly pledged allegiance to IS in April 2018. It named its leader as Abu Yasir Hassan, and declared him a global terrorist.