Before Gen. Qassem Soleimani was killed by a drone strike outside Baghdad’s international airport in the early hours last Friday, he was hardly a household name in the United States. The White House — which had ordered the killing — immediately set about framing the assassination along the same lines as the death of Abu Bakr al-Baghdadi a few months previously, or that of Osama bin Laden in 2011. America had just defeated one of its greatest enemies, officials said.

But that Soleimani, the commander of Iran’s Quds Force — the country’s elite external military wing — was a relatively unknown figure among the American public not only attests to his skill as an officer of clandestine warfare, but also the extremely complicated relationship he had with the United States. Just a few years earlier, Soleimani had been an indispensable figure in the fight against the Taliban and ISIS.

Soleimani’s ability to be both foe and occasional ally to the U.S. was part of his trademark style of warfare — which was so successful that it led many commentators to brand him the most skilled officer operating in the Middle East. According to Dr. Arshin Adib-Moghaddam, a world politics professor at SOAS University of London and author of the forthcoming book What Is Iran? Domestic Politics and International Relations in Five Musical Pieces, Soleimani created “a regional axis that is both institutionalized and ideological,” which could “translate into versatile military and political action whenever necessary.” Soleimani could simultaneously fight Israeli forces in Lebanon through Hezbollah (to the detriment of Washington) while conducting operations against the Taliban in Afghanistan (to Washington’s benefit).

Iran’s occasional collaboration with the U.S. began right after 9/11. While the Trump administration has repeatedly claimed that Iran was at least partially responsible for the attacks, Tehran actually used the occasion to express its sympathy with the American people, denounce the Taliban and recalibrate its relations with Washington. According to Dr. Marvin Weinbaum, director of the Afghanistan and Pakistan program at the Middle East Institute, Iran not only opened up its airspace to give aid to the initial American invasion of Afghanistan but was “absolutely critical in bringing the various factions of the mujahedeen and the Northern Alliance together.” That eventually culminated in the creation of Afghanistan’s current Constitution. Weinbaum believes that Soleimani was instrumental in the collaboration, which was brought to a swift end following President Bush’s 2002 declaration that Iran was a part of the “Axis of Evil” alongside Iraq and North Korea.

Whatever residual good feelings remained between Washington and Iran entirely evaporated in the early years of the Syrian Civil War. During that conflict, Soleimani propped up the embattled Assad regime against pro-democracy protesters, foreign intervention and, later, Islamist factions such as the Nusra Front and, by 2014, ISIS. While the Syrian Civil War represented a nadir of American-Iranian relations, with America-backed militias fighting Iranian-backed militias, the rise of ISIS provided a marriage of convenience. Alongside ISIS’ anti-American slant, according to Adib-Moghaddam, the terror group also had a “virulently racist anti-Iranian, anti-Shia agenda.”

Perhaps no military action better displayed Soleimani’s willingness to collaborate with the United States than the September 2014 Siege of Amirli, a small Shiite Turkmen town in Iraq. Fearing that ISIS intended to commit genocide, Iran and American-backed forces, with direct air support from both countries, lifted the siege in what was to turn out to be one of ISIS’s most stinging defeats. The Siege of Amirli was just one instance of Iranian-American collaboration to fight ISIS, all of which took place alongside the warming of relations between the two countries before the signing of the 2015 nuclear agreement. But this de facto alliance had its limits. Adib-Moghaddam opined that the “politics of the conflict made it largely impossible for the two countries to integrate their strategic preferences into a coordinated approach.”

While Trump has sought the lion’s share of the credit for destroying ISIS, Adib-Moghaddam says it was Iran, along with Russian air power and Kurdish forces, that “dealt the decisive blows.” And Soleimani was the mastermind behind it. “Irrespective of the politics and biography of the man, the killing of Soleimani made the world that much more dangerous to live in,” says Adib-Moghaddam, “and this insecurity is the real bond that binds common Iranians and Americans together and which should mobilize them as a part of a global movement against war, both here and there.”

Still, many in Syria and Iraq are celebrating Soleimani’s death. “He represents to many Syrians the terrorist arm of the mullah’s regime in Iran,” says Eyad Hamid, a Syrian journalist. “Syrians outside Assad regime-controlled areas were jubilant about his assassination, regardless of the Trump administration’s motives behind this move. For them, Soleimani is no less involved in their misery than Assad.”

Meanwhile, his assassination appears to have united Iranians against America weeks after protests showed growing disenchantment in cities like Tehran against the Islamic regime. It is a reminder that just as Soleimani’s relationship with the U.S. was complex, so too will be his legacy in the Middle East.