BEIRUT (Reuters) - Syrian and Iraqi forces closing in on the last scraps of Islamic State’s caliphate straddling the remote border area between the two countries have already witnessed the jihadists’ likely response.

A flag of Islamic State militants is pictured above a destroyed house near the Clock Square in Raqqa, Syria October 18, 2017. Picture taken October 18, 2017. REUTERS/Erik De Castro

While their comrades mounted last stands in their Syrian capital of Raqqa and the city of Hawija in Iraq, IS militants seized the Syrian town of al-Qaryatayn and launched its biggest attack for months in Ramadi late last month. That is the kind of guerrilla insurgency both countries foresee IS turning to.

“It is expected that after the Daesh terrorist organization’s capacity to fight in the field is finished, its remnants will resort to this type of (guerrilla) operation. But for a certain period of time, not forever,” said a Syrian military source, using an Arabic acronym for Islamic State.

The continued ability for IS to mount attacks in areas where it was thought to have been eliminated will hinder efforts to stabilize regions when the fighting wanes.

In Iraq, where Islamic State originated, it has a proven record of falling back upon local networks from which it can rise anew when conditions allow. So far, it has not shown it has the same capacity in Syria, and it might find doing so more challenging there than in Iraq.

The sectarian divisions on which it thrives are less pronounced in Syria, and it faces competition there for jihadist loyalty from other powerful militant groups.

“Daesh is in essence an Iraqi organization, it will survive to some extent in Iraq. Syrian members will dissolve in other Syrian Salafi jihadist groups,” said Hisham Hashami, an adviser on Islamic State to the Iraqi government.

But in both countries it has shown it can exploit holes left by overstretched enemies to carry out spectacular attacks - the one in Syria’s al-Qaryatayn most clearly - that spread panic and tie down opposing forces.

It has also proved able to carry out bombings and assassinations in areas controlled by the Iraqi and Syrian governments, U.S.-backed Kurdish militias and rival jihadist rebel groups, signaling an ability to survive underground.

A jihadist from a Syrian rebel faction opposed to Islamic State said the group had won enough support among young men to give it a latent capacity to revive.

“I believe that it is possible, given that its ideology has spread widely among the youths, that something new will emerge,” the jihadist said, pointing to the highly effective propaganda machine deployed by Islamic State over the last three years.

TERRIBLE SPEED

The al-Qaryatayn attack began on the evening of 29 September, when up to 250 militants with guns, rockets and mortars spread around the area with “terrible speed”, said Ayman al-Fayadh, a resident.

It was particularly alarming because the government had declared al-Qaryatayn safe months ago, and had helped its residents to move back into their homes.

When the jihadists were finally forced out after three weeks of fighting around the outskirts of al-Qaryatayn, they took their revenge, slaughtering scores of its inhabitants. “They were very bloodthirsty and didn’t spare anyone,” Fayadh said.

The Syrian military source said it took three weeks to retake the town because it was inhabited and the army was trying to avoid civilian casualties.

However, the attack showed how towns in Syria’s deserts, where armed forces can be spread only thinly, are vulnerable to Islamic State and that such operations can tie down opposing armies.

“People are afraid of Daesh returning,” said a Syrian journalist who visited the town this week. “They killed anyone who had taken part in pro-government protests. Bodies had been thrown in streets and in wells.”

Fayadh also said townspeople were among the attackers, indicating that Islamic State used its years of rule to build local support networks and establish sleeper cells for future attacks - something that could be replicated elsewhere in Syria.

“They’re going to continue to have to look for places where they can plan and finance and resource and launch their attacks from,” said Colonel Ryan Dillon, spokesman for the U.S.-led coalition, noting Islamic State had often used “sparsely populated areas”.

The assault on Ramadi took place three days before. Militants attacked Iraqi security forces with suicide car bombs, mortars and machine guns in a city that it had apparently lost months earlier.

GUERRILLA WAR

The big challenge in both Iraq and Syria is to co-opt the Sunni Arab tribes, or risk a revival of jihadist insurgency.

The Suuni-Shi’ite divide has plagued Iraq since the U.S.-led invasion in 2003 that ignited the civil war. Shi’ite parties backed by Iran have dominated the government and used militia forces against mostly Sunni insurgents.

The Syrian government may have the same problem. It is allied to the region’s main Shi’ite powers - Iran and militia groups such as Lebanon’s Hezbollah - and led by a president, Bashar al-Assad, from a Shi’ite offshoot sect.

It will also be a challenge for the U.S.-backed Syrian Democratic Forces (SDF) alliance in northern Syria, which is spearheaded by Kurdish groups. They have sometimes struggled to convince Arabs that it will protect their interests.

“It all depends on the degree to which those fighting under Assad and the SDF incorporate settled tribes into governing structures,” said Andrew Tabler, a fellow at the Washington Institute for Near East policy.

Even in northwestern Syria, where rebel groups including jihadist factions hold sway, hardship and insurgent infighting might create space for Islamic State to again seize ground.

Beside the al-Qaryatayn attack, a group of Islamic State fighters have managed to take a pocket of territory in rebel-held areas near Hama in recent weeks, battling a rival jihadist group for control of several villages.

It has used bomb attacks and assassinations to target government-held cities in the west, Kurdish security forces in the northeast and Islamist rebel factions in the northwest.

In the isolated enclave it holds in Yarmouk camp south of Damascus, it has also shown renewed aggression, taking over the headquarters of a neighboring rebel group this month by force.

The jihadist rebel said he believed Islamic State could repeat the strategy it used in Iraq last decade of retrenching when under attack, then rebounding in more virulent form.

“In this period of weakness, Islamic State depends on the ideology that it spread,” the jihadist said.

“It appears that the same experience is being repeated. They could carry out bombings, a guerrilla war.”