Protesting security forces drove Tunisia's top leaders from a memorial ceremony Friday for two policemen killed by militants, in a sign of growing frustration over the costly fight against jihadists.

President Moncef Marzouki, Prime Minister Ali Larayedh and parliament speaker Mustapha Ben Jaafar were confronted by members of the security forces, some in uniform, shouting "Get out!" during the official ceremony at a military barracks in the Tunis suburbs.

The same slogan became a rallying cry during the 2011 uprising that ousted Tunisia's former strongman Zine El Abidine Ben Ali and touched off the Arab Spring.

"We won't accept the presence of politicians," shouted one of the protesters, as many of the demonstrators carried placards demanding laws to protect the police.

The Tunisian leaders, who had been waiting in an office at the barracks, left after about 20 minutes of jeers from the crowd, without attending the ceremony.

Larayedh later criticised the incident as "unacceptable" and said appropriate measures would be taken against the minority involved, while the commander of the National Guard, Mounir Ksiksi, vowed the offenders would be prosecuted.

The prime minister insisted Friday's protest could not be linked to Tunisia's security forces in general, which he praised for doing a "remarkable job."

But a spokesman for the security force unionists involved in the demonstration defended his colleagues, calling their "spontaneous reaction of anger and pain ... normal behaviour in the circumstances."

"The leaders were not targeted. It (The protest) assumed proportions that we did not want," Imed Belhaj Khelifa said.

With the departure of the three top officials, only Interior Minister Lotfi Ben Jeddou remained for the memorial service.

The two policemen were killed on Thursday by an armed group in the Beja region, 70 kilometres (40 miles) west of Tunis.

The interior ministry said earlier that during a military offensive the security forces had killed several members of the group suspected of carrying out Thursday's attack, which also left one policeman wounded.

Security force unions have organised several demonstrations in recent months to condemn the lack of resources for combatting Tunisia's jihadists, who have carried out a string of attacks since the 2011 revolution.

But this is the first time police representatives have directly blamed the country's top leaders, who normally attend memorial ceremonies for police and soldiers killed in combat.

In a separate incident last December, Marzouki and Ben Jaafar were forced to flee a ceremony in the poor central town of Sidi Bouzid to mark the two-year anniversary of the revolution that started there.

On that occasion, protesters disappointed with the government's failure to improve living conditions heckled them and pelted them with stones.

Since December, security forces have been tracking a group of militants allegedly linked to Al-Qaeda in the Chaambi mountain region along the Algerian border, with some 15 soldiers and police killed in the operations.

Despite air strikes and a major military offensive launched in July, the militants remain active, with clashes reported as recently as last weekend.

The two policemen killed on Thursday were trying to verify the presence of an armed group sheltering in Beja, about 100 miles (160 kilometres) north of the Chaambi region.

Lack of resources against jihadist threat

The defence ministry has admitted lacking the resources needed to confront the jihadist threat, notably equipment to clear the mountainous border region of mines placed by the jihadists that have proved highly effective against the security forces.

Tunisia was plunged into crisis in July when opposition politician Mohamed Brahmi was shot dead by suspected jihadist gunmen, in circumstances similar to the murder of another opposition MP, Chokri Belaid, six months earlier.

Tunisia's radical Salafist movement Ansar al-Sharia has been implicated in both killings, with the interior ministry saying its leader, Abou Iyadh, and the suspected gunmen themselves are currently holed up in Mount Chaambi.

The ruling Islamist party Ennahda, which shot to power in 2011 parliamentary polls, is frequently accused by the opposition of failing to rein in the country's armed extremists.