Maputo (AFP) - Suspected jihadists on Monday attacked military barracks and ringed a northern Mozambican town, hoisting their flag a few kilometres from a major gas exploration site, police said.

The attack took place in Mocimboa da Praia, where a shadowy jihadist group first launched its offensive in October 2017.

Locals call the group Al-Shabaab but it is not linked to a group by the same name operating in battle-scarred Somalia.

"Evildoers burst into the main town of Mocimboa da Praia and began exchanging shots with the defence and security forces," national police commander Bernardino Rafael told reporters in the capital Maputo.

He said fighting was still going on and called on inhabitants to be wary of insurgents who "may want to infiltrate".

Police spokesman Orlando Mudumane said the attack was launched before sunrise and that the insurgents had "hoisted their flag" in the town.

Another police officer in Mocimboa da Praia told AFP "the attackers surrounded virtually the entire small town and now control the air base, the port and the police stations".

"They placed barricades on the road to prevent reinforcements from arriving," the officer said.

The faceless group has killed more than 700 people, according to the medical charity Doctors Without Borders (MSF) -- causing hundreds of thousands to flee the gas-rich region and raising concern among energy giants.

While the insurgents have so far mainly targeted remote villages, Monday's attack was directed at Mocimboa's military headquarters in Cabo Delgado, Mozambique's northernmost province.

Mocimboa da Praia has not been targeted by jihadists since October 5, 2017, when its members stormed a police station and a military post.

French company Total owns a $25 million stake in a liquified natural gas project around 60 kilometres (40 miles) from Mocimboa da Praia.

President Filipe Nyusi vowed to stem the Cabo Delgado attacks after he was sworn in for a second five-year term in January.

But government troops have been struggling to restore order, despite pressure by oil giants to deploy more soldiers in the area.