ALEPPO, Syria — As a rebel fighter shined his flashlight onto a clump of blankets and clothes scattered around the concrete basement floor, I wondered if this was where my friend Sultan had spent the last moments of his life. A goofy, gap-toothed 22-year-old who worked for a local fixer, he was part of a group of Syrian activists, journalists and rebel fighters who had been arrested by the Islamic State of Iraq and Syria and taken to this makeshift prison in the basement of a former hospital.

The building had served as the Sunni extremist group’s headquarters in Aleppo, Syria’s largest city, but now the pitch-dark corridors were deserted. By the stairs, we found a long cable of copper wires taped together. One of the rebels picked it up and mimicked a whipping gesture — former prisoners who were held here reported being tortured. Farther down was a room that served as a cafeteria, with signs in English attesting to the presence of foreign jihadists among ISIS’s ranks. “Fear Allah! Remember that he is watching you so please do not waste food and clean up after you have eaten,” read one. Another advised “brothers who want to receive their families from outside Syria” to coordinate with the “Mujahedeen Services Office.”

ISIS began as the Iraqi affiliate of Al Qaeda but split off at the beginning of this year over its ambitions to expand into Syria and establish itself as a new caliphate. After its stunning takeover of much of western Iraq last month, it now calls itself simply the Islamic State.

But ISIS is gone from Aleppo, having been forced out by local Syrian rebels in January. This military reversal, one of the group’s few, highlights the dilemma facing the West: Its best potential allies against ISIS are other Sunni Islamists.