This is the final chapter in a groundbreaking investigation by Pulitzer-Prize-winning reporter Roy Gutman that documents Bashar al-Assad’s sinister contributions to the creation of the so-called Islamic State. It demonstrates the dictator’s complicity in the horrors that ISIS has imposed inside Syria while plotting and inspiring terrorist attacks in Europe and the United States. These are all facts that President-elect Donald Trump should take into account when he talks glibly about working with Russia and Assad to fight against ISIS.

As we saw in the previous two chapters, Assad first tried to ingratiate himself with Western leaders by portraying the national uprising against him in 2011 as a terrorist-led revolt. When that failed, he released jailed Islamic extremists who’d fought against U.S. troops in Iraq, then staged phony attacks on government facilities, which he blamed on terrorists. Far from fighting ISIS, Assad looked the other way when it set up a state-within-a-state with its capital in Raqqa, and then left it to the U.S. and others to try to take the battle to the Islamic extremists.

REYHANLI, Turkey—In the spring of 2012, hundreds of militant Islamists crossed into eastern Syria from Iraq under the eyes of the Assad regime’s extensive security apparatus. As they arrived, Syrian intelligence services received two sets of instructions.

One was in writing, and contained the names and details of the jihadists, along with the instruction to “arrest and kill them.”

But that was the cover story. Even as it circulated a “kill” order, the regime sent out official messengers to convey the opposite message.

“They came from command headquarters and held meetings of the intelligence offices,” said Mahmoud al Nasr, a former intelligence official in northern Syria who defected in October 2012. ‘They told us: ‘stay away from them. Don’t touch them.’”

The jihadists arrived in groups of three, sometimes five, then it became hundreds, he said. “Everyone of them started to bring his friends,” al Nasr said. The majority joined Jabhat al Nusra, a group that publicly declared its affiliation with al Qaeda in April 2013 and then split into two groups, Nusra and the Islamic State. Some of the infiltrated jihadists joined Ahrar al Sham, a third and seemingly more moderate Islamist group.

The conflicting instructions sheds light on the little-known relationship between the Assad regime and the Islamic State. Assad claims that his domestic political opposition are all terrorists intent on destroying the Syrian state and regularly appeals to the international community for help in battling terrorism. But the regime in fact facilitated the buildup and expansion of the real terror group in Syria.

Yet a two-year investigation reveals a more complex picture, for the regime has mounted operations in collaboration with Islamic State and at times has fought it, sustaining serious losses.

“Sometimes they are allies. Sometimes they are enemies,” Massoud Barzani, the president of the Kurdistan Regional Government in Iraq said in a recent interview with The Daily Beast. “Sometimes they cooperate with one another. Sometimes they fight each other.” What is the pattern? “Only God knows,” Barzani said

What is clear is that the Assad regime has a long-established relationship with the Islamic State, dating back to the war in Iraq, when Syria funneled thousands of volunteers to fight the U.S. occupation. It jailed well over 1,000 jihadists on their return, only to release them in 2011 as Syrians staged a national uprising against the regime. And many of those are the leaders of ISIS today.

The overall pattern was to facilitate the jihadists, with just enough clashes that the regime could say it is fighting them.

Following their arrival in 2012, the regime looked the other way as the extremists seized government bases. It also allowed convoys to travel back and forth from Syria to Iraq and did nothing to stop ISIS from shipping weapons into Iraq, leading to the ISIS conquest of Mosul in June 2014.

Today, the Syrian regime drops barrel bombs and fires missiles at ISIS-held towns but its targets are usually civilians. The frontline between the two forces has been mostly quiet.

“The regime has mostly ignored ISIL,” said Karin von Hippel, a former State Department official who worked on the Syria issue for six years until November, 2015.

“You would be hard pressed to find many instances of the regime attacking ISIL—and the few sporadic attacks that have taken place have targeted more civilians than ISIL fighters.”

Van Hippel, who now heads the Royal United Services Institute, a London think tank, was using an alternative name for the Islamic State.

Secretary of State John Kerry went further in November 2015, when he said that ISIS was “created” by Syrian President Bashar al Assad, who released 1,500 jailed jihadi prisoners, and former Iraqi premier Nouri al Maliki, who released 1,000.

Assad wanted to be able to say, “it’s me or the terrorists,” Kerry said after the Paris terror attacks.

In March, the Syrian regime took on the Islamic State, and aided weeks of Russian air bombardment and ample help from the Lebanese Hezbollah militia, it reclaimed the ancient city of Palmyra from the Islamic State.

Yet there are a lot more examples where the regime facilitated the extremists’ capture of territory from rebel forces. Officials in Iraq, where the Islamic State and its Sunni partners now occupy as much as one third of the country, a key role to Assad in the rise of the Islamic State.

“He helped establish the route through which international terrorists came in from Syria to fight Americans in Iraq,” said Saeed al Jayashi, at the time a member of the country’s national security council staff. He was referring to a period 10 years ago when foreign jihadist volunteers flocked to Iraq to battle U.S. troops. “And the same routes were used to bring terrorists into Syria.”

“I myself believe there is some form of high coordination,” he said, though he acknowledged he did not know how it was carried out.

***

The first step in the build-up of ISIS was in October 2011 when Abu Bakr al Baghdadi, at the time the head of al Qaeda in Iraq, reportedly dispatched Mohamad al Jolani, a militant leader named who was to form Jabhat al Nusra, the al Qaeda affiliate in Syria.

Then in the spring of 2012, jihadists began arriving from Syria. “The regime knew about their arrival and knew they were in the countryside, moving among villages. It didn’t target them,” said Nabeel Dendal, who’s from eastern Syria and defected from the government in June 2012.

“In some cases, we would submit a name” to higher command and say, ‘this person is in my area,’” said al Nasr, the former intelligence official from northeastern Syria. “I didn’t get any orders from the leadership to watch him. The regime would not supply any more data on him.”

Tribal chiefs in the border area recognized the fighters returning to Syria, according to Salman Sheikh, former head of the Brookings Center think tank in Qatar who regularly convened prominent Syrian figures to plot the country’s future. “They saw these guys cross their doorsteps between 2003 and 2005, and now they saw them with their own eyes, not just coming back but finding a fairly open reception,” he said. “Nobody from the government challenged them.”

By late 2012, when the United States labeled the Nusra Front a terrorist organization, the group had turned into an effective anti-regime fighting force.

In April 2013 Baghdadi announced the creation of the Islamic State of Iraq and Syria (ISIS), but Jolani, who’d developed popular local support for fighting the regime, refused to shut down Nusra. The two groups became bitter rivals.

Soon, Baghdadi’s ISIS began to consolidate its power in eastern and northern Syria. In May that year it took over Raqqa from Nusra forces and began seizing towns across northern Syria from U.S.-backed moderate rebels. ISIS gained ground rapidly by opening its doors to volunteers from other less radical Islamist groups and by recruiting volunteers from abroad to bolster its numbers.

ISIS had few, if any, confrontations with the Syrian military, which continued to operate a major base outside Raqqa. Even after ISIS raised an enormous black flag at offices over former Syrian government offices, and made it its de facto capital, effectively claiming sovereignty over state territory, no Syrian aircraft targeted those locations.

In its Raqqa sanctuary, ISIS has operated like a state-within-a-state. It introduced its extreme version of Islamic law, staged public executions, and persecuted the Christian population until it fled. Most ominously, ISIS sent weapons, men and supplies to its forces elsewhere in Syria and back and forth to Iraq, as the Syrian military, to all accounts, looked on.

As it consolidated its hold on north Syria, ISIS announced a military offensive against the western-backed rebels, which it called “Expunging the Filth.” It took over the principal border crossings the rebels relied on for Western and Gulf-supplied arms and logistics, took over rebel bases and checkpoints and kidnapped western and Syrian reporters and held them for ransom. ISIS also assassinated rebel commanders, abducted others, put them on trial and then executed them in public.

***

When Abu Khalil enlisted in the Islamic State of Iraq and Syria in late spring 2013, he was hoping that its weapons, finances and manpower would make the al Qaeda affiliate a tougher foe of the government of President Bashar Assad than Ahrar al Sham, the Syrian Islamist group with which he’d been fighting.

The 26-year-old security guard at Aleppo University went through one-month basic training and wore a suicide belt loaded with TNT when he took part in battles to capture Syrian government military bases. But he declined to pledge bayat, the lifetime loyalty oath, to his local emir and to Baghdadi.

“I was with them for six months, but I didn’t understand anything about them,” said the former fighter, who asked to be identified by a nickname that means “Khalil’s father” for his own protection. “I didn’t understand their political aims and demands. As for Baghdadi, I don’t know him, so how can I make the pledge?”

Abu Khalil, who was interviewed in a friend’s apartment in Reyhanli, southern Turkey in December 2014, was puzzled at the ease with which ISIS seized bases. “Sometimes you’d feel that (the Syrian army) were giving up and withdrawing without a fight,” he said. “Were they afraid of al Qaeda because al Qaeda has suicide belts? Or was there cooperation with the regime? I didn’t manage to find this out. It is the biggest question of all.”

Two thirds of the ISIS fighters were foreign, according to Abu Khalil, who said he reported to a Tunisian emir along with fighters from Chechnya, Spain, Germany, Turkey, Jordan, Iraq, the Gulf region, and north Africa. Instruction at the training camp he attended was in English, but there was a translation into Arabic.

“If they saw someone smoking a cigarette or who didn’t have a long beard, they’d say he was a kaffir (infidel) and threaten to cut his head off,” he said. His emir labeled Nusra, the group they’d just broken with, “apostates” and forbade contacts with Nusra members.

To attract foreign fighters, ISIS offered material benefits: a salary, and even more important, a wife. “They would come and immediately get married. They would buy cars,” said Abu Khalil, available at the fire sale prices.

“And the leadership would give them money and support.” He said ISIS would pay the dowry for a Syrian bride, usually in the range of $1,000, but often give sums much higher, up to $4,000. But Syrians were shut out of the bonanza, and that’s one reason many of them quit ISIS, Abu Khalil among them. He left the organization in September 2013.

One of the most biggest puzzles at the time was how ISIS disposed of weapons it captured. “When we got loot from military bases, we never saw any of it,” he said. Later, he learned that most of the weapons they captured had been sent to Iraq.

***

One of the early examples of the Assad regime supporting the expansion of ISIS through military power was in Al Bab, just northeast of Aleppo, which fell to ISIS in September 2013.

“We had 500 fighters in the area and needed reinforcements in Al Bab,” recalled Isam al Nayif, then with the Liwat al Tawhid brigade of the Free Syrian Army, now living in Nizip, southern Turkey. As rebels dispatched reinforcements from nearby Minbij, ISIS sent a convoy from the vicinity of a government base to the west, in Kuweires. “We intercepted a radio call ordering the Air Force to bomb the convoy coming from Minbij,” he said. Twenty-five rebels were killed. But the ISIS convoy proceeded unhindered, and the rebels abandoned Al Bab. (Syrian Kurdish forces, aided by U.S. airstrikes and a U.S.-organized force of Arab tribes, recently ousted ISIS from Minbij.)

By late 2013, many Syrians in ISIS were convinced that the group was collaborating with the Assad government. In a lengthy video posted on YouTube in March 2014, one former Islamic State fighter, Riad Eed, who said he was from Mar’ea, a town in Aleppo province, cited repeated instances in which Islamic State forces stood by watching as Syrian government troops seized town after town from the moderate opposition.

Eed, who is now in hiding and could not be contacted, said that whenever he urged his ISIS colleagues to fight government troops, the response was: “No, no, Sheikh. There are enough Mujahidin to fight them. There is Jabhat al Nusra, and they are enough for the fight,” he recounted.

When Safira, a major town south of Aleppo, was about to fall in late October 2013, ISIS’s 500 fighters in the area were “watching from afar and doing nothing,” he said. When the Tawhid brigade, a part of the Islamic Front umbrella group, sent reinforcements, ISIS blocked them. “When I asked about that, they said it is forbidden to resort to infidels for help,” Eed said.

Government capture of the town led to the flight of its 130,000 inhabitants, according to Doctors Without Borders. Capture of the city gave the regime full control over arms factories there, which soon began churning out barrel bombs that it dropped over Aleppo throughout 2014.

And most of Hasakah province in northeast Syria fell to ISIS in February and March 2014 after ISIS sent forces in a convoy of some 300 vehicles from Ash Shaddadi—unmolested by Syrian warplanes, according to Nasr, the former intelligence official.

Direct confrontation between ISIS and Assad forces have been relatively rare. In July, 2014, Assad’s air force began bombing some ISIS facilities and the next month ISIS overran the last government-held military bases outside Raqqa, executing hundreds of Syrian soldiers.

Some of the evidence of collusion on the battlefield is circumstantial, based on Assad’s failure to counter the expansion of Nusra and later ISIS. Some is based on intelligence.

A senior Turkish official, interviewed in Ankara, said that its radio intercepts had captured a Syrian military commander telling Islamic State militants that they should vacate an area before 6 a.m. because aerial bombing would begin then. In another intercept, a regime commander was overheard suggesting giving an award to the Islamic State for its active cooperation.

“If you look at the dynamics, the regime never bombed an area controlled by ISIS,” the official said. “When ISIS left they bombed, or they bombed an area before ISIS began its offensive.”

“There is a behind-the-scenes partnership between them and the regime,” Ahmet Davutoglu, the former Turkish prime minister, said early last year.

His remark was borne out on the battlefield.

***

When the regime bombed Raqqa in November 2014, it missed every significant ISIS military target but killed dozens of civilians, anti-government observers say. When the Islamic State attacked Syrian army bases, executing captive troops, Assad’s forces have been slow to respond and the attack ineffectual.

In Al Bab, also under Islamic State control in northern Syria, U.S. aircraft destroyed an Islamic State headquarters on Dec. 28, 2014 and inadvertently killed only civilians being held there. But days earlier, Syrian Air Force planes bombed parts of the city and hit no significant Islamic State installation, according to residents. The regime continues to bomb only civilian targets in Al Bab.

When ISIS attacked the ancient city of Palmyra and the entire district of Tadmur in May 2015, the Syrian army evacuated many of its bases in advance, put up only a modest defense and let its weapons warehouses to fall into the radicals’ hands. As this was under way, the regime and ISIS engaged in perhaps the most clearcut of all the cases of collaborate.

In Spring 2015, as it was reeling from its losses in northern Syria, the Assad regime reached out to Islamic extremists in a bid shift the balance on the battlefield.

Rebel forces had just taken the entire Idlib province and ISIS had seized Palmyra, but the shrunken, demoralized Syrian army was unable to reclaim either.

After a meeting between regime and ISIS representatives at a major gas production facility in the east Syrian town of Ash Shaddadi on May 28, ISIS military convoys set out from Raqqa and other towns under its control for Mar’ea, a town north of Aleppo, which sits astride a critical supply route from Turkey.

There, as regime aircraft pounded the positions of moderate rebel forces, Islamic State fighters moved in to occupy them. They captured one third of the town before rebel reinforcements arrived and beat them back.

A U.S. official confirmed the collaboration.

“We’ve seen Assad providing air support for ISIS. There has to be some kind of an agreement there,” said a Defense Department official, who spoke anonymously because he wasn’t authorized to be quoted by name. He added: “This has happened more than once.”

Turkish security officials revealed the date, location and participants at the meeting, and this reporter was able to corroborate the main elements.

ISIS attack on Mar’ea in June 2015, supported by the regime, was a stunning blow. ISIS sent convoys of up to 60 vehicles across northern Syria to reach the border area and got within six miles of the actual crossing. Rebel forces from other areas headed to Mar’ea and prevented ISIS from cutting the access road to Turkey over which humanitarian and military supplies flow to Aleppo.

A more recent example of apparent collusion was in October 2015, when rebels had to abandon a former infantry school north of Aleppo that they’d captured in December 2012. ISIS attacked head on with tanks, heavy artillery and car bombs but couldn’t it capture the location, a spokesman for the defending Al Safwa battalion said.

Then, as regime aircraft bombed the school, ISIS fighters first moved around the town to cut off the escape route. After losses of as many as 70 fighters, the rebels abandoned the position to ISIS, which turned it over to regime forces.

Last February, rebels collected photographic evidence that the regime and the Islamic State are in an effective non-aggression pact. Drones sent up along the 35-mile front between the Assad regime and ISIS, they found there were no fortifications on either side of the line and no signs of fighting, said Usama Abo Zaid, legal advisor to the Syrian opposition. “There are a few fighters on the front line, but far too few to be at war with each other.”

He said the Islamic State continues to send car bombs as their weapon of choice against moderate rebel forces, but not against the Assad forces or its allies, even against the Kurdish militia, the People’s Protection Force, with the United States has allied itself. And as the regime with heavy Russian air backing ended the rebel siege of the towns of Nubul and Zahra, “ISIS didn’t fire a bullet,” he said.

Few observers think the apparent collaboration between the regime and ISIS will last forever. For now, however, they are working in parallel.

The reason is obvious, says Bassam Barabandi, a former Syrian diplomat now living in Washington, D.C.

“They know they cannot both survive, but before they reach that final step of war, they should kill all the moderates. Here they are working together closely,” he said.

—with additional reporting by special correspondents Mousab Alhamadee and Zakaria Zakaria