“We are in a battle, and more than half of this battle is taking place in the battlefield of the media,” Ayman al-Zawahiri, then al-Qaeda’s second-in-command, purportedly wrote in a 2005 letter to Abu Musab al-Zarqawi, the Jordanian who led al-Qaeda in Iraq at the time. The previous year, Zarqawi’s network, originally known as Tawhid and Jihad, had publicly released more than 10 beheading videos, including a video believed to show Zarqawi himself beheading the American businessman Nicholas Berg. This was bad PR, Zawahiri cautioned his hotheaded field commander, and risked alienating Muslims.

Zarqawi was killed in a U.S. airstrike in 2006, but the hyper-violent form of sectarian jihad he pioneered emphatically lives on in the form of ISIS, the direct descendent of al-Qaeda in Iraq. While the group hasn’t exactly followed Zawahiri’s counsel about winning hearts and minds, it has proven fantastically adept at exploiting new social media to disseminate its message. Indeed, it is no exaggeration—although it may now be clichéd—to say that as well as being one of the most savage terrorist groups in the world today, ISIS also has the slickest propaganda. Its media arm Al Ḥayat has produced hundreds of films, ranging from three-minute beheading videos to hour-long features improbably combining elements of travelogue, historical documentary, and atrocity porn. Many are high-quality productions involving Hollywood-style techniques and special effects. One video, titled Clanging of the Swords, Part 4, drew particular praise from the late New York Times media critic David Carr, who wrote, “Anybody who doubts the technical ability of ISIS might want to watch a documentary of Fallujah that includes some remarkable drone camera work.”

“Media is more than half the battle" also happens to be the motto of the U.S. State Department’s Center for Strategic Counterterrorism Communications (CSCC), founded in 2010 as the world’s first government-sponsored enterprise not run by an intelligence agency to counter online jihadist propaganda. The phrase is emblazoned across the opening PowerPoint slide in all CSCC presentations, according to the CSCC’s coordinator Alberto Fernandez. Alongside this quote is a second one, taken from the purported memoir of the American jihadist Omar Hammami, who until his death in 2013 was a leader in the Somali Islamist militant group al-Shabab: “The war of narratives has become even more important than the war of navies, napalm, and knives.” Then-Secretary of State Hillary Clinton sounded a similar theme in describing the office’s mission a year after it was founded; it was vital, she said, to diminish the appeal of terrorism, and the CSCC was focused on “undermining terrorist propaganda and dissuading potential recruits.”

“It’s not about Louis Armstrong and isn’t jazz great and America loves Muslims,” Fernandez told me over a coffee recently, describing what he saw as the general tenor of previous public-relations efforts at the State Department after 9/11. “It’s not about quoting the secretary of state, because that’s boring, that’s lame. Our focus is not on the positive message. What we do is counter-messaging. We’re the guys in the political campaign that [do] negative advertising. We’re in people’s faces.”

Despite joining the fray relatively late, the CSCC is now at the forefront of what Hammami and Fernandez have both called “the war of narratives,” and has produced well over 50,000 online “engagements” in four languages—Arabic, Urdu, Somali, and English. An engagement in the State Department's terminology can be anything from one of the hundreds of “mash-up” videos the team assembles out of pre-existing footage—in many cases from ISIS’s own videos—to tweets or graphics highlighting the depredations and hypocrisies of the jihadists.

In addition to this, the CSCC’s so-called digital outreach team (DOT) crashes various online forums to troll ISIS sympathizers and regularly jumps onto pro-ISIS Twitter hashtags. For example, in April last year, an ISIS supporter created an Arabic hashtag translating to “#accomplishmentsofISIS.” Almost immediately the Arabic DOT used the same hashtag to post a series of sarcastic references to ISIS’s “accomplishments” at, variously, “starving people of #Aleppo,” “destroying mosques in #Riqqah,” “crucifixion of young men,” and “squatting, looting and damaging homes.” All of these messages linked to incriminating YouTube videos detailing ISIS atrocities in Syria. The CSCC has even entered into dialogue, if it can be called that, with actual jihadists, including Hammami, with whom Fernandez said it “exchanged barbs” in Arabic over Twitter. “He was clearly troubled,” Fernandez recalled. “I felt sorry for him. He was killed by al-Shabab, not the Americans. We actually referred to his death in one of our videos—‘see what happens if you join these guys.’”

But unlike their counterparts at the hard military end of the battle against ISIS, the American foot soldiers in the war of narratives are at a considerable disadvantage relative to their jihadist adversary.

ISIS has beheading videos. The CSCC doesn’t. Beheading videos are shocking and repugnant. But they are also weirdly fascinating—and they go viral for this reason. The CSCC’s videos, by and large, are not shocking or repugnant, still less fascinating—and don’t go viral for this reason. ISIS’s métier is shock and gore, whereas the CSCC’s, to put it unkindly, is more mock and bore, more Fred Flintstone than Freddy Krueger. Shock and gore, needless to say, is where the action is—and hence where the Internet traffic tends to go. “You’re never going to be able to match the power of their outrageousness,” Fernandez said, conceding this disadvantage.

ISIS has a vast network of “fanboys,” as its virtual supporters are widely and derisively known, who disseminate the group’s online propaganda. (ISIS ennobles them with the title “knights of the uploading.”) They are dedicated, self-sufficient, and even, Fernandez said, occasionally funny. And they are everywhere on Twitter, despite the social-media network’s efforts to ban them. Fernandez described the group’s embrace of social media as “a stroke of genius on their part.” The CSCC doesn’t have fanboys.

More crucially, ISIS has a narrative. This is often described by the group’s opponents as “superficial” or “bankrupt.” Only it isn’t. It is immensely rich. The International Centre for the Study of Radicalisation and Political Violence estimates that of the 20,000 or more foreign jihadists believed to have gone to fight in Syria and Iraq, around 100 are from the United States. These fighters may be naive or stupid, but they didn’t sacrifice everything for nothing. John Horgan, director of the Center for Terrorism and Security Studies at University of Massachusetts Lowell, told me that people who join groups like ISIS “are trying to find a path, to answer a call to something, to right some perceived wrong, to do something truly meaningful with their lives.”

The CSCC doesn’t have a narrative—not one, at any rate, remotely comparable in emotional affect and resonance to that of ISIS. No one is more sharply aware of this than Fernandez himself. “ISIS’s message,” he said, “is that Muslims are being killed and that they’re the solution. ... There is an appeal to violence, obviously, but there is also an appeal to the best in people, to people’s aspirations, hopes and dreams, to their deepest yearnings for identity, faith, and self-actualization. We don’t have a counter-narrative that speaks to that. What we have is half a message: ‘Don’t do this.’ But we lack the ‘do this instead.’ That’s not very exciting. The positive narrative is always more powerful, especially if it involves dressing in black like a ninja, having a cool flag, being on television, and fighting for your people.”

In his biography of the philosopher Ludwig Wittgenstein, Ray Monk discussed Wittgenstein’s decision to enlist in the Austro-Hungarian army during the First World War. It wasn’t really about patriotism, Monk suggested. Rather, Wittgenstein “felt that the experience of facing death would, in some way or other, improve him. ... What Wittgenstein wanted from the war was a transformation of his whole personality, a ‘variety of religious experience’ that would change his life irrevocably.” One of the greatest challenges in counterterrorism today is working out how to create a narrative that directly speaks to a similar kind of longing among potential terrorists—and channels that longing in a nonviolent direction. As Scott Atran argues in Talking to the Enemy, “In the long run, perhaps the most important counterterrorism measure of all is to provide alternative heroes and hopes that are more enticing and empowering than any moderating lessons or material offerings.”

The more immediate, but no less intractable, challenge is to change the reality on the ground in Syria and Iraq, so that ISIS’s narrative of Sunni Muslim persecution at the hands of the Assad regime and Iranian-backed Shiite militias commands less resonance among Sunnis. One problem in countering that narrative is that some of it happens to be true: Sunni Muslims are being persecuted in Syria and Iraq. This blunt empirical fact, just as much as ISIS’s success on the battlefield, and the rhetorical amplification and global dissemination of that success via ISIS propaganda, helps explain why ISIS has been so effective in recruiting so many foreign fighters to its cause.

Zawahiri was right: Half the battle is media. But the other half—the reality on the ground—is the more important part of the equation. And as long as that reality supports ISIS's narrative, its message will continue to appeal to disaffected Sunnis both within and outside the Muslim world. This is not lost on Fernandez, either: “Saying ISIS is bad is not good enough. There has to be change on the ground. Messaging can shape and shade, but it can’t turn black into white.”