ISIS is murdering and enslaving across Syria and Iraq. Russia is deploying dozens of aircraft to support the regime in Damascus. Huddled masses have been tempest-tossed into Europe. At the eye of the storm, Bashar al-Assad is pursuing a cynical, brutal, and risky strategy to cling to power.

Assad’s plan, it seems, is to deliberately aid the rise of ISIS—what I call the devil’s gambit. The logic is simple and ruthless: radicalize the opposition so that the Syrian dictator looks like a lesser evil to domestic and foreign audiences. Here, Assad benefits from the inherently polarizing nature of civil war, as a cycle of atrocities and revenge pushes all sides to the extreme. He has further spurred radicalization by focusing the regime’s fire on moderate enemies, while reportedly releasing jihadists from jail and purchasing oil from ISIS. In recent months, the Syrian military allegedly used air strikes to help ISIS advance toward the city of Aleppo. Khaled Khoja, a Syrian opposition leader, claimed that Assad’s fighter jets were acting as “an air force for ISIS.”

In the widening gyre, the center cannot hold. Back in 2011, the relatively moderate Free Syrian Army seemed a plausible candidate to lead the resistance against Assad. Now the leading rebel factions include ISIS, the Islamic Front, and the al-Nusra Front, which is affiliated with al-Qaeda. The U.S. effort to train a moderate Syrian force has proved to be a pitiful and quixotic quest. After 10 months and millions of dollars, the United States has created a rebel army that is five strong. Not 5,000 strong, or 5 percent of the opposition. But literally five guys—barely enough to run a burger joint.

The tyrant and the terrorists have a symbiotic relationship. While ISIS rails against the secular regime, its focus is on building the caliphate, not getting rid of Assad. Meanwhile, ISIS’s advance in Iraq in 2014 was a godsend for the Syrian regime. The insurgents headed away from Damascus. And the group’s capture of the city of Mosul and much of Anbar province terrified the West. A reluctant Barack Obama could not accept the fall of Baghdad, and authorized extensive air strikes against ISIS.

For both Western countries and Assad’s Alawite constituency at home, the choice is stark: the devil you know, or a pack of rapacious demons. If Assad were to fall, the chief beneficiary would be the very Islamist forces that the United States is bombing. To be reminded of the dangers of toppling a dictator, U.S. officials need only look to Libya, where the overthrow of Muammar al-Qaddafi in 2011 led to anarchy. Assad is the TINA candidate: There is no alternative.

The devil’s gambit, then, appears to have succeeded. The Obama administration has recently backed away from insisting that Assad must relinquish power, and signaled instead that the dictator could stay in power for a transitional period as part of a peace settlement.

But the key word here is “appears.” As with the pact between the Nazis and the Soviets in 1939, the partners in Syria’s dance of death will happily stab each other when the moment is opportune.

Assad’s endgame, it seems, is to clear the field of any relatively moderate groups around which Syrians and the international community might coalesce, and then build a coalition to defeat ISIS head-on. He will inherit a desert wasteland, but it’s still an inheritance.

In striving toward this goal, however, Assad faces a serious problem. His gambit may have worked in Western capitals, but he’s hemorrhaging strength closer to home. The regime has suffered a string of battlefield reversals, losing thousands of soldiers and pulling back to strategic locations like Damascus. By one estimate, Assad now controls only about one-fifth of Syria—a strip of territory snaking along the western edge of the country.

Assad’s deteriorating position has left his great-power patron, Russia, wondering whether the dictator is a viable long-term bet. The Kremlin has moved significant military assets to aid the Assad regime and, on Sunday, announced a deal with Syria, Iran, and Iraq to share intelligence in the fight against ISIS. Just days earlier, Vladimir Putin said, “Our main goal is to protect the Syrian state.” But note: He didn’t say he would protect Assad personally. After all, the Syrian dictator is a means to an end: defending Moscow’s interests in the country and the region—including its naval base at Tartus, the only Russian military facility outside the former Soviet Union. As Fyodor Lukyanov, a foreign-policy advisor to the Kremlin, commented in August, “Russia still believes [Assad] should stay, but cannot ignore that the general situation is changing, that the strategic position for Syria is much worse now than before.”

These two key dynamics—the radicalized opposition and the Syrian military’s struggles—have pushed the United States and Russia closer to a deal where Assad plays a transitional role in a new regime. The reformed Syrian government would reach out to moderate opposition and then direct its fire against the Islamist ultras, in concert with the West and regional players.

This outcome closely resembles Assad’s preferred endgame: Damascus versus the barbarians. The key question is whether Assad himself stays in charge. It all hinges on the definition of “transitional,” and the willingness of the Russian and Iranian governments to back Assad to the hilt. As a ruthless survivor, Assad may fancy his chances of being a permanent provisional president. He may even offer to step down—right after terrorism is defeated in the Middle East.