Fighters from Somalia's al-Shabab militia celebrate their alliance with al-Qaida in the Islamic Maghreb in February 2012. .

British citizens have been instructed to leave Somalia immediately after the government warned it was "aware of a specific threat to Westerners" in the breakaway East African region of Somaliland.

The Foreign Office did not provide any further details, but said "kidnapping for financial or political gain, motivated by criminality or terrorism" was a threat throughout the country.

"We are now aware of a specific threat to Westerners in Somaliland, and urge any British nationals who remain there against our advice to leave immediately," the Foreign Office said in a statement.

The advice comes days after a warning from European countries of a "specific and imminent" threat to foreigners in the eastern Libyan city of Benghazi.

That in turn followed the militant attack on the In Amenas natural gas complex in Algeria near the Libyan border earlier this month, in which 38 hostages were killed.

Somalia's al-Qaida-linked al-Shabab militant group threatened earlier in January to kill a French hostage, Denis Allex, who was the subject of a botched rescue attempt by France's military.

French president Francois Hollande declared military operations against Islamist rebels in neighbouring Mali, where factions of al-Qaida in the Islamic Maghreb, including tribal Tuaregs and members of former Libyan leader Muammar Gaddafi's armed guard, have taken up arms against their own government since returning home after their defeat in Libya.

Weapons smuggled into Libya during the civil war are now being funnelled to neighbouring countries.

UK Prime Minister David Cameron warned earlier this month of a growing militant threat in North Africa, which he called a "magnet for jihadists".