Some analysts saw this as the Islamic State trying to have it both ways: punishing Turkey for starting to act against it, but leaving enough of a gray area that it avoids a full-on clash with a country that has been valuable to its operations.

Still, there has clearly been a shift.

“Since mid-2015, a significant rise in pejorative references to the Erdogan government in Islamic State propaganda has indicated Turkey is now in its cross hairs,” Mr. Smith said, adding that this kind of rhetoric also preceded attacks in Western Europe and beyond. “An increase in terrorist attacks in Europe, in North Africa, in Bangladesh and in the Caucasus region were all preceded by increased focus on these areas in Islamic State propaganda materials.”

The group’s long honeymoon with Turkey started with the country’s aid to rebel groups that were fighting the government of Bashar al-Assad of Syria, often with the blessing of Western intelligence agencies, according to analysts. At the start, the Islamic State fit into that category, though it then began focusing more on eliminating competitors than fighting Mr. Assad.

Among the competitors the group was killing were Turkey’s avowed enemies: Kurdish separatists sheltering in Syria and Iraq. Turkey’s Western allies began accusing it of clinging to ambivalence toward the Islamic State. Even when it began strikes against the group last summer, its actions against the Kurds were more numerous and intense.

The centrality of Turkey for foreign volunteers flocking to the Islamic State is evident in court documents and intelligence records. Dozens of young men and women were arrested by the F.B.I. in the United States and by officials in Western Europe after they booked flights to Istanbul. Because so many of the group’s foreign fighters passed through Istanbul’s Ataturk Airport, the destination itself became synonymous with intent to join ISIS.

By 2015, the group was advising recruits to book round-trip tickets to beach resorts in southern Turkey instead, and to be sure to spend a few days pretending to be a tourist as a ruse.

That was the technique used by Reda Hame, a 29-year-old Parisian recruit. He explained to interrogators last summer, after he was arrested upon returning to France to carry out an attack, that he had made sure to buy a package stay at a beach resort in southern Turkey specifically because he wanted to throw off investigators, who knew to look for suspects heading to Istanbul. “I bought an all-inclusive holiday so that I could pass myself off as a tourist,” he said, according to a transcript of his interrogation by France’s domestic intelligence agency in August.