Their militancy soon crossed the border. After the initial stage of mobilizing volunteers and weapons for jihad in Afghanistan, a second phase developed in which Pakistan witnessed a wave of anti-Shiite violence, including bombings of Karachi’s major Shiite mosques by the Taliban’s sister organization in Pakistan, Sipah-e Sahaba.

The Turkish government’s decision to turn a blind eye to Islamic State activity within its borders has similarly led to the extremists’ increasing influence in certain areas of Turkey’s major cities. The recent and unprecedented arson attacks on Shiite mosques in Istanbul may indicate that Turkey is entering this second phase. Turkey is home to only a small Shiite community; but Turkey’s Alevis, a heterodox Muslim sect often regarded as heretical by Sunnis, constitute about 20 percent of Turkey’s population.

A campaign by Sunni extremists against the Alevi community could lead Turkey into a Pakistan-like vortex of sectarian violence and radicalization. The present government’s own politics of polarization, illustrated by Mr. Erdogan’s baiting of the opposition leader Kemal Kilicdaroglu due to his Alevi background during Turkey’s recent presidential election campaign, may further inflame sectarian tensions. And Islamic State militants will not hesitate to exploit the Sunni-Alevi fault line in Turkish society.

Pakistan’s final and most dangerous stage of extremism occurred when the flow of militants and resources was reversed. As the Taliban conquered most of Afghanistan, it provided training camps and other logistical support to its allies, making it harder for Pakistan to control militant organizations inside its borders. After 9/11, Gen. Pervez Musharraf attempted to crack down on militants inside Pakistan. His efforts culminated in the 2007 Red Mosque battle in Islamabad and the subsequent coalescing of militants into the movement known as the Pakistani Taliban.

Turkey has not experienced this stage yet. But the Islamic State may find fertile recruiting ground among Turkey’s 1.3 million Syrian refugees. And Turkish citizens may be drawn into the orbit of militancy just as segments of Pakistan’s population have been. If the Islamic State’s Turkish networks remain intact, Turkey runs the risk that homegrown militants will be empowered by the return of fighters from Islamic State territory in Syria and Iraq.

Ms. Bhutto’s strategy of employing militant proxies to create a client state in Afghanistan succeeded — but at a high price for Pakistan. That is a warning for Turkey, which must recognize that it cannot shield itself from Sunni militancy while pursuing a Sunni sectarian foreign policy in the Middle East.