Britain will offer to work alongside Algerian forces on counter-terrorism as part of a joint security partnership announced by David Cameron in Algiers on Wednesday evening.

Cameron, on the first visit to Algeria by a British prime minister since the country's independence in 1962, said his aim was to help the country "help itself" amid a growing threat from al-Qaida-linked terrorists in the region.

His offer of a joint security compact – including access to UK intelligence and the deployment of a limited number of British soldiers – comes in the wake of the attack on an Algerian natural gas plant that left 37 foreigners dead, including up to six Britons.

At a press conference following the talks, standing alongside the silent Algerian president, Abdelaziz Bouteflika, Cameron promised the two countries would stand together in the fight against terrorism. He said: "Both Britain and Algeria have suffered from terrorism and we understand each other's suffering".

Cameron said the two sides wanted to form a strategic partnership on policing, defence, counter-terrorism and intelligence. "The threat in parts of Pakistan, Yemen and Somalia is clearly more of a threat than the al-Qaida terrorism that is clearly growing in Mali today, but because it is growing we should not ignore it."

Britain is hoping detailed talks on closer security co-operation will start in the spring, with a progress report in the summer to both prime ministers. The British side is to be led by Sir Kim Darroch, Cameron's national security adviser.

British soldiers would work alongside Algerians on a limited number of operations, but the chief focus would be on shared intelligence, border security and countering extremist propaganda.

The aim will be to share best practice on security – increasing the exchange of information between security experts, on issues such as border and aviation security; counter improvised explosive devices; and tackling extremist ideology and propaganda.

Cameron has also asked the Algerian authorities to participate in a joint contingency planning exercise and to discuss how the two countries can share best practice on crisis response and resilience planning.

The prime minister said the attack on the gas plant and the situation in Mali "reminds us of the importance of partnership between Britain and countries in the region". He added: "We will be announcing a strengthened security partnership between our countries. I would stress the greatest threat of terrorism in this region is to the countries of this region.

"Of course there are potential threats to the UK but the focus is very much on helping these countries to protect their security and protect British people in this region. It is very much about helping the region to help themselves."

The compact is also designed to give British advice on how to tackle the cross-border jihadists operating in Algeria and Mali. Cameron is highly exercised that a new terrorist generational struggle may be growing in north Africa liable to match the threat previously focused in Pakistan and Afghanistan.

Cameron was frustrated by the Algerians' unwillingness to seek western help or advice during the siege of the gas plant, although he acknowledges the Algerian government, given the number and armoury of the jihadists, faced no good option.

In his talks Cameron was expected to raise the mixed communications between the two governments during the hostage crisis, including the fact that Cameron had to ring the Algerian prime minister, Abdelmalek Sellal, to confirm his security forces had launched an assault on the plant.

Sellal resisted foreign help partly to demonstrate its independence to its own people, but the attack, the worst in the oil and gas industry's 150-year history, is prompting the industry to review its security and investments.

The Algerians have been struck by Cameron's eagerness to travel to the country in the wake of the attack. Cameron was already flying to Liberia this week for an aid conference, but shelved a visit to Ghana in order to see the Algerians.

But Cameron has to calibrate his joint security compact carefully. Algeria is likely to be resistant to the idea of drones, European or American, flying over its territory, and will point to the unhappy experience in Pakistan which has seen US drones inflict multiple civilian deaths.

The oil and gas sectors account for 70% of the national budget, mainly in the southern Algerian desert, and the In Anemas plant accounts for 6-7% of Algeria's reserves of gas. The energy sector was not targeted during the Algerian civil war which broke out in 1992. But the new terrorist groupings see even the heavily guarded plants as legitimate targets.

The plant was in a militarily secure zone, yet the heavily armed jihadists, as many as 40-strong, reached the plant without detection, and appear to have infiltrated the Algerian workforce, providing expert knowledge of the layout of the sprawling plant.

Overseas energy workers have long needed personal protection in Algeria to avoid opportunistic kidnappings, or to avert the occasional bus bombing, but the scale of this premeditated attack has led to fears for the security of the Algerian energy fields.

It is also likely to lead to a rise in oil workers' danger money, and even requests from some of the energy firms for a change in the tax regime. Mokhtar Belmokhtar, the leader of the Mali-based Katibat al-Moulathamine (Masked Brigade), renewed threats against Algeria in January 2013, accusing it of allowing the French to use its airspace for military operations in Mali against Islamists there.

In north Africa, al-Qaida in the Islamic Maghreb – originally an Algerian franchise of the global terror organisation – has successfully aligned itself with a local extremist group in Mali named Ansar Dine, or Defenders of the Faith, and together they have in effect taken control of the northern two-thirds of Mali.

Cameron and Sellal had not met before but spoke six times by phone during the attack on the gas plant.Algerian government response to the terrorist attack, and the failure to notify him in advance of the security forces' assault. But he is trying to focus on the future rather than indulge in recriminations. The compact is also designed to give the fiercely independent Algerian government advice on how to track jihadists crossing over the Algerian border with Mali.