As the tide turns against Islamic State (IS) forces in the battlegrounds of the Middle East, some veteran jihadis are expected to return to their former stomping grounds in areas of Afghanistan and Pakistan near China’s western borders. And when they do, they will be welcomed by an advance party of fighters from Iraq and Syria who moved to eastern Afghanistan last year to help Taliban defectors establish the “Khorasan governorate”.

Islamic State claims surprise attack on Pakistan police academy that left 59 dead

About 70 IS fighters had arrived in Afghanistan by September 2015, according to a report by the United Nations’ al-Qaeda/Taliban Monitoring Team, which found that IS Khorasan had been recruiting followers in 25 of Afghanistan’s 34 provinces. It controls several districts of Nangarhar province and has established pockets elsewhere in the country, despite being targeted by US and Afghan forces and, separately, by the Afghan Taliban.

“Right now, we see them very focused on trying to establish their caliphate, the Khorasan caliphate, inside Afghanistan,” General John Nicholson, commander of US and NATO forces in Afghanistan, said in an interview with NBC News.

The growing threat posed by IS to the war-torn region was underlined by two attacks last week. A team of three suicide bombers killed 61 people and injured 165 others in an assault on a police training school in the Pakistani city of Quetta, while some 30 villagers were abducted and executed in Afghanistan’s Ghor province.

Pakistan and Afghanistan are no strangers to veteran jihadists; both hosted militants who fought for al-Qaeda against US occupation forces in Iraq between 2003 and 2006. Their leader, Jordanian militant Abu Musab al-Zarqawi, lived in the northwestern Pakistani city of Peshawar for nine years, prior to the September 11 attacks in the United States.

Hand-picked Afghan and Pakistani militants from groups allied with al-Qaeda subsequently undertook “live training” tours of Iraq under the tutelage of al-Zarqawi, who was killed by a US airstrike in June 2006, and others who have since assumed positions of responsibility in IS. While there, they learnt new tactics and skills – notably the use of improvised explosive devices and suicide bombs – and introduced them in Afghanistan and Pakistan when the insurgencies there gathered momentum in 2005.

Using those relationships, Abu Bakr al-Baghdadi took refuge in the Datta Khel area of Pakistan’s North Waziristan between 2012 and 2013, before emerging as IS chief, according to Mansur Mahsud, director of research for the FATA Research Centre, an independent Islamabad-based think-tank.

Has Chinese pressure forced Pakistan U-turn on anti-India terror groups?

The first mass defection of foreign al-Qaeda-affiliated militants based in Afghanistan and Pakistan to IS was announced in October 2014 by the Islamic Movement of Uzbekistan, a battalion of several hundred militants notorious for their involvement in high-profile attacks against Pakistani military installations. Similarly, some 1,000 Uygur militants from the restless western Chinese province of Xinjiang ( 新疆 ) moved to Syria from Pakistan’s tribal areas; about half joined the ranks of al-Nusra Front, an al-Qaeda affiliate, while the other half switched allegiance to IS.

Another associate of al-Zarqawi, Abu Huda al-Sudani, became the first Arab militant based in Afghanistan to switch allegiance from al-Qaeda to Islamic State in April 2014. He was instrumental in securing a pledge of allegiance to the IS leadership in Raqqa from the leaders of six Pakistani Taliban factions who established the Khorasan governorate.

Some 500 Pakistanis are fighting for IS in the Middle East, out of the estimated 25,000 to 30,000 foreign fighters there, according to the ‘Global Terrorism Index – Vision of Humanity’ report issued in November 2015 by the Institute for Economics and Peace, an independent think-tank based in New York.

Why are Malaysia, Singapore nervous as Iraq looks to retake Mosul from Islamic State?

With the terrorist group fast losing territory in Iraq and Syria, “some IS leaders and their supporters may come to Afghanistan and areas of Pakistan as well,” Khawaja Khalid Farooq, head of Pakistan’s National Counterterrorism Authority between 2011-2013, said.

“It is plausible they will move to hideouts in Afghanistan, although the Taliban are a much stronger force there. Problems will also be created by Pakistani fighters upon their return,” he said.

Tom Hussain is an Islamabad-based journalist and Pakistan affairs analyst