In Mosul, it was obvious, the jihadists would make their grand last stand. Smaller fights would follow, but this would be the showstopper. It would be not just the biggest and most devastating battle of this war, but the biggest battle, in a sense the culminating battle, of what was once known as the war on terror. When it was only half done, a Pentagon spokesman would call the fighting in Mosul “the most significant urban combat since WWII”. I was in Mosul when I read that. I had gone to Iraq for the first time in the summer of 2016, to write about life in the Islamic State’s wake. I got a month-long visa. I ended up staying the better part of a year.

Every CTS [Iraqi Counter Terrorism Service] position I saw in Mosul was as insecure as the one in Zahra [in the east of the city]. No checkpoints, no regular sentries, sometimes not even a perimeter. Locals wandered in and out. The soldiers were usually obliging. Near the triage station in Gogjali, on a slope overlooking east Mosul, was a nascent neighbourhood, a scattering of freestanding structures, half-finished homes, cinderblock foundations. Some were inhabited by their owners or refugees, others abandoned. One of the latter, a modest one-storey house that once aspired to two storeys, had held enemy fighters or served as a stopping place for them as they tried to escape the city. On the cement floor of the small courtyard was a discarded Rhodesian ammunition chest rig and by that, in a sink, a pile of hair of what had once been a beard. Occasionally you came upon just such perfect tableaux.

CTS had moved in. To my untrained eye, this at first appeared to be just another command post in a requisitioned home like the one in Zahra. Someone better versed than myself in the instruments of high-tech warfare would have understood the significance of the large aerials on the roof and on the APC [armoured personnel carrier] idling in front. What I noticed was that, on the ground floor, the soldiers who sat on the overstuffed wall-to-wall sofa smoking and drinking tea and studying their phones, as they would have done in any command post, were also shooting covetous glances at the stairwell, on which they were not permitted. It wasn’t until I ascended the stairs that I saw why this was: on what would have been the second level, and was now instead a kind of terrace, was the coalition’s forward air command. From here the air war on Mosul was being directed.

It was a sparse and alarmingly vulnerable affair. To the south, the terrace was blocked from view by a wall, the only wall. The rest was surrounded by a waist-high parapet, meaning it was exposed on three sides. From a decent vantage to the north or west or east, you could have monitored it, or shot at it, or shelled it. There didn’t appear to be such a vantage, but then there didn’t appear to be much of anything, so filled was the air with smoke and dust. That the place was never blown up by the jihadists seems a miracle.

Facebook Twitter Pinterest Members of the Iraqi forces pose for a photograph as troops advanced in Mosul’s eastern Al-Intisar neighbourhood in 2016. Photograph: Ahmad Al-Rubaye/AFP/Getty Images

On any given day there were several Iraqi generals on the terrace and officers from at least three different national militaries. The operation revolved around an Iraqi colonel, the joint terminal attack controller. He was the nexus among the CTS field commanders, the Iraqi high command and the coalition, and, happily for everyone, he was one of the best-liked officers in CTS, a favourite of foreigners, particularly of the Americans. He spoke perfect American English and perfect American military jargon in a perfect American accent that he had either picked up on a stateside base or won through a Higgins-esque gift for mimicry. He discussed helos and mike-mikes [ammunition calibres] with total confidence. A pair of two-way radios and a quartet of smartphones passed in endless cycle through his hands. Sometimes he handed a phone to one of the pair of air controllers who sat at a folding table facing onto the city. The two men wore CTS uniforms, but that was a ruse. Fine of feature and haughty of glance, they could have been spotted as European, and specifically Gallic, from one of the Reaper drones flying 20,000ft above us. They spoke rapid-fire French to one another and slow English and Arabic to the others. They monitored a tablet computer that displayed camera feeds from the UAVs [unmanned aerial vehicles] and typed on a laptop whose screen was tiled with chat windows. It was through these that strike requests were relayed and discussed. Over the radios came British, Australian, and American accents from various coalition offices and aircraft.

When things were busy, everyone doing their job and appreciating the others doing their jobs, the strike requests coming in, being passed up the chain, being granted, the bombs coming in, rumbling the city, the terrace was a nervy, comradely spectacle, and it gave you a glimpse of the grandeur, if I can use that word, of this war, of war. There was no better outcrop from which to bear witness to the sheer mystical velocity of 21st-century mechanised digitised combat. Words were spoken, words were written, and then missiles hurtled from the sky. Words into bombs. Speech into death. The jihadists may have believed they were carrying out God’s will, but the men on this terrace could summon it.

I would find out later that the strike request exchanges were taking place on a WhatsApp channel. Armies, air forces, an infinity of munitions, and it was all being orchestrated via a free chat application you download to your phone in five seconds. I didn’t know whether to be amazed or appalled. I was amazed and appalled. It was farcical. It was ingenious. It was perhaps the single densest example of a technological current in the war I could only think to call occult. And once you started noticing them, the occult techno-wrinkles were everywhere. There was that magical GPS mapping application the troops had on their phones, like a self-aware cellular sand table. There were the videos of engagements, uploaded and transferred instantaneously, so that fighters on one front could get their lolz or shed their tears watching fighters on another. There were the privately recorded videos of executions and torture, shared around the theatre on WhatsApp and Signal and Telegram, uploaded by jihadists and soldiers alike, dwarfing in number and sometimes in horror the official videos the al-Hayat media centre put out. Everyone knew someone who’d been killed on the internet. There were the pictures on Facebook – soldiers with prisoners, soldiers with rubble, soldiers with body parts, soldiers with corpses, soldiers with Americans, soldiers with their mothers. Anything would do. One infantryman showed me a picture of him in Baiji, standing in front of his Humvee before the flattened cityscape holding a giant blue teddy bear. Another showed me a picture of his three-year-old son at home handling a pistol. (“I want him to learn to fight.”) Aside from everything else happening on it, Facebook was hosting a kind of underground war economy. I met a Yazidi woman who was captured by the jihadists and brought to Syria. She escaped with the help of a people-smuggler her husband found on the site. You could sit for hours at a checkpoint or in a command post with the troops as they scrolled through one app after another, browsing this cyber-hem of the war, and I often did. But anyone in the world who wanted to tune into this fight could, without filters. Never had a war been so uncensored.

The technology could get to be too much. I knew an intelligence officer whose impossible job it was to stand in the waves of Moslawis [citizens of Mosul] as they fled from embattled neighbourhoods, asking their names. He was like a lone pier pole in a typhoon. When someone took pity on him and stopped, he would check their name against a database of suspected jihadists which he held before him on an iPad. One day I saw him and asked how many names the database had grown to.

“Thirty-eight thousand,” he said.

“How many matches have you had?”

“Four.”

Facebook Twitter Pinterest Iraqi special forces monitor Isis positions from the inside of Mosul’s university in January 2017. Photograph: Dimitar Dilkoff/AFP/Getty Images

Then there was simple talking on the phone. In its modest way, this was the most astounding technological achievement of all. Isis forbade phones and disabled the cell towers and televisions in Mosul. In liberated neighbourhoods you’d see green circles with lines through them spray-painted on the walls on corners. These were signs from the jihadist engineers that meant the satellite dishes on that block had been confiscated or disabled. But this was 2016, for God’s sake. God himself couldn’t have got rid of all the cellphones in Mosul if he’d wanted to. Moslawis found ways to keep their phones and to talk on them, lying down below parapets in the dead of night, whispering, crouching in closets, climbing into bushes in gardens. It was impossible to truly enslave anyone in a country where 3G was standard.

The jihadists took pictures, too. A disturbingly high percentage of them included house cats. They loved cats because the prophet Muhammad is said to have loved cats. I defy you to find a stranger image than a bearded man in a headscarf holding aloft an assault rifle in one hand, pointing to the heavens with the index finger of the other, while beside him, staring into the lens, is a cat.

I would love to know the mental acrobatics the camera-shy Baghdadi [Abu Bakr al-Baghdadi – leader of Isis in Iraq] went through to sanction all this. He knew the internet and social media were essential to his success, and yet he was too sanctimonious and too old (born in 1971, we think) to be entirely comfortable with it. What was that pitch meeting like? You see, my Caliph, what we’d like to do is live as though it’s the seventh century, as you suggest, except for the apps.

Sometimes the men on the terrace left off talking and typing to gaze onto the smouldering city. What did they feel, if anything, I wondered. Accomplishment? Vindication? Awe? Mortification? They couldn’t see the death they caused, not really. You almost never saw someone die in an airstrike. Usually they destroyed buildings. If the missile hit a jihadist vehicle or mortar team in the open, the drone cameras might pick up a body or body part. But that was rare. You saw the plume, maybe a large piece of frag spiraling slowly in the air. With the air so thick, though, mostly you just heard and felt the impacts.

Facebook Twitter Pinterest The ruins of Mosul’s university after it was recaptured in 2017. Photograph: Dimitar Dilkoff/AFP/Getty Images

Naturally, Washington claimed that the accuracy of this air war was second to none. So-called deliberate strikes on Isis positions and assets, the result of surveillance and intelligence work-ups, were so vetted, so pinpoint, American military officials assured journalists, that the number of accidental civilian casualties would prove vanishingly low. Even the dynamic strikes, the spontaneous responses to the strike requests being called in by field commanders, had to be approved by a chain of generals and lawyers that stretched from Mosul to Baghdad to Florida. If you were on the US central command email list, you received from MacDill air force base, in Tampa, a daily email, subject heading “strike release”, that listed the previous day’s targets in Iraq and Syria. Sometimes there were several, sometimes several dozen, but no matter how many there were, Centcom implied, with a lack of any information to the contrary, every strike was a resounding success. Every missile hit its target and only that, destroying X piece of jihadist equipment or X piece of jihadist-held infrastructure, killing X number of jihadists. At the bottom of every email was this explainer: “A strike, as defined in the coalition release, refers to one or more kinetic engagements that occur in roughly the same geographic location to produce a single, sometimes cumulative effect in that location.” And this disclaimer: “These strikes were conducted as part of Operation Inherent Resolve, the operation to destroy Isis in Iraq and Syria. The destruction of Isis targets in Iraq and Syria also further limits the group’s ability to project terror and conduct external operations throughout the region and the rest of the world.” But standing on that terrace, if you were being honest with yourself, you had to smell horseshit. The missiles were coming in constantly and they were being directed by a bunch of guys using WhatsApp in an abandoned building. How accurate could they really be?

In the early days of the battle, the Iraqi generals were what I called welcoming, but what any military professional in a less companionable country would, rightly, call wildly indiscreet. They allowed me and other journalists to hang out on the air command terrace all day. The French-speaking pair regarded us with indifference. The only people who clearly wanted us to leave – certainly the most advisable attitude – were the Americans, but they deferred to their Iraqi counterparts. Every morning a special forces contingent pulled up to the air command in a fleet of jaunty new joint light tactical vehicles. It was never clear who they were, whether Seals, Green Berets, Army Delta, or something else. They wore no unit insignia nor rank indicators and no one was going to ask. They looked exactly as you had come to expect such men to look since those officially unofficial photos of bearded commandos on horseback had trickled into American newsrooms from the Hindu Kush in late 2001: mid-to-late 30s, rangy, nimble, watchful, reproachful, bearded, bearded with beards that seemed to grow as much from their modified MP5 and SR-25 rifles as their faces, beards with their own air of predation. They didn’t acknowledge you aside from an expressionless glance, maybe a quarter-inch nod if they understood you to be American. The one time I exchanged words with one, I offered him a coffee. The better roadside groceries on highway two stocked cold, sweetened Turkish coffee, the cans barrel-shaped and heavy, and I always carried at least a half dozen in my backpack, along with at least two packs of cigarettes, to smoke myself and to offer to Iraqi soldiers as an ice-breaker.

“Coffee?” I said, holding up a can to a square-jawed, blue-eyed, golden-bearded man on the terrace.

“No, thanks,” he said, politely and in such a way that we could share in the grovelling irrelevance of the gesture and his contempt for me.

Facebook Twitter Pinterest Civilians approach Iraqi government forces during the fighting in 2016. Photograph: Odd Andersen/AFP/Getty Images

In Iraq, the Mosul offensive had at least two names. The first was Operation Fatah. The word means victory or conquest in Arabic, and refers specifically to the conquests of the first century of Islam. The Iraqi media tended to prefer Operation Nineveh We Are Coming, or, sometimes, Operation We Are Coming Nineveh. Both versions made the offensive sound like a number from Godspell, but at least you felt pangs of solidarity when you saw NINEVEH WE ARE COMING superimposed in the upper corner of Iraqi television newscasts. The same could not be said for the name used by the Americans, who insisted on calling it Operation Inherent Resolve. Another of the Pentagon’s witless fumblings for meaning, this. Leaving aside the contradiction – either something is the product of resolution or it is inherent, it is not both – inherent as opposed to what, you had to ask. Extrinsic? Provisional? Was there some lesser theatre of this war being treated to Operation Incidental Appointment? “Inherent Resolve” had a faintly begrudging air, too, I always thought, as though Washington were saying to Baghdad “We’ll help you, because we are exceptionally principled people, not because we don’t blame you for your mess.”

Combat in east Mosul stretched into the new year. By the middle of January 2017, the Iraqi troops were in shooting distance of the Tigris. On the 13th, they captured Mosul University. The immense campus, which once accommodated 30,000 students, spread down a slope toward the river. After seizing the university two and a half years earlier, Isis had closed the social science, earth science, humanities, literature, and art departments, everything but the medical and engineering schools. A young man I met who had been pursuing a history degree once asked a jihadist why. What was the point of forbidding the study of even Islamic history?

“We have a new history,” the jihadist told him. “We have the right history.”

It was rumoured the chemical engineering department had been kept open so chemical weapons could be manufactured. Whether or not this was true, the coalition felt it necessary to bomb the university painstakingly. After Iraqi troops secured the campus, journalists rushed there, hoping to find who knows what, beakers of green bubbling liquid, maybe. What they found instead was hill after hill of rubble. It was by far the most devastated quarter of east Mosul. This didn’t intimidate the students and professors who were clamouring to return to class. Within days they were back on the campus.

Among the charred remains of the academic buildings, you could see evidence of that brief period of Moslawi-American bonhomie in 2003. There were American-donated computers and books and furniture. Professors spoke to me fondly of [US army general] David Petraeus, who had made building up the university a priority. Now both the Nineveh provincial government, working in exile from Irbil, and Baghdad claimed they had no money to help mend the campus, so the students and professors had begun taking matters into their own hands, fixing and cleaning, bringing supplies and tools from home. I met a group as they gathered in the vestibule of the languages and literature building, where the jihadists had set alight a pile of desks and bookshelves. The building was equipped with a sprinkler system and the flames had been quickly extinguished. Students were now pushing brooms across the slate floor towards the entranceway, sweeping out begrimed water and wood shards. One leaned his broom against the wall and approached me. Would I like to see the building? he asked. Indeed I would. We walked the halls. He pointed into empty classrooms, telling me which courses had been taught in them. I nodded and made loud noises of approval. We looked in at the language lab, where two professors were repairing a window frame.

Facebook Twitter Pinterest A soldier from the Iraqi special forces reassures members of a family who took shelter inside a building held by troops during fighting against Isis in 2016. Photograph: Odd Andersen/AFP/Getty Images

“I don’t see the reason we’re not back here studying,” the student, whose name was Karam, told me. “There’s everything. There’s chairs.”

He was an English literature major, and, outside of the occasional minor syntactical error, spoke marvellous English, with a grasp of obscure idiom and a talent for both immodesty and self-effacement.

“This used to be my classroom. I sat at the front, of course.”

“Teacher’s pet?” I asked.

“Not really. Because I’m smart, not because I love teachers. I love to study. Our studies were interesting. I wasn’t the best student in high school because we had physics and mathematics and stuff. I don’t like those stuffs. English is really my passion. Shall we go on?”

As we ascended a flight of stairs, a courtly presence materialised at my side. “My favourite professor,” Karam said.

“I teach English poetry,” the professor said. “Renaissance. Wyatt, Surrey, Raleigh. Wyatt was the first one to bring Italian poetry into English, you know. Then he was the first to define the sonnet.” None of which interested the jihadists, of course. “They said that poetry is forbidden. Haram, they called it.”

Unlike many of his colleagues, who found work in other parts of the country, the professor had stayed in Mosul under the caliphate. He’d taken the time to translate into Arabic a dictionary of literary symbols and to read a lot of Donne. “I like how he expressed his feelings through ideas.” He’d reread Macbeth, too, because it felt relevant. “But especially the poem that is appropriate for our situation. In the Islamic State, thought stopped. Only survival mattered. We only move. We can just move. Eat and sleep. Mind stops.”

Macbeth also meant a lot to Karam, a theatre buff with a gothic bent. He’d been working on a paper about Marlowe’s Doctor Faustus when the department was closed. He was fascinated, he told me, by “the deal that the doctor made. The idea is interesting. To see how he suffered. How he gave himself to the devil, for a purpose, and then he lost everything. He wasn’t happy.” The resonance with jihadism was enough that neither of us had to remark on it.

Facebook Twitter Pinterest Iraqi students at the University of Mosul as they arrive to take their exams on June 13, 2017. Photograph: Mohamed El-Shahed/AFP/Getty Images

We walked into the English library. Miraculously, the jihadists hadn’t touched it. I read out titles, seeing what caught Karam’s fancy. Lord of the Flies. Didn’t know it. Portrait of the Artist As a Young Man. Maybe he’d read it. Jane Eyre. Boring. Joseph Andrews… ”

“So boring,” Karam said, which was how he felt about most of the alleged classics he’d been made to read. “We read Wuthering Heights as first years. It’s really boring too. Truly, I think that. And most other students think that as well.” While waiting for the university to reopen, he’d read 30 novels, some for future coursework, some for pleasure. The highlight, the book from which he’d learned the most about human nature and the dark depths of the soul, he said, was Stephen King’s Pet Sematary. Certain resonances with jihadism occurred to me and perhaps to Karam as well. He and a classmate were trying to convince their professors to introduce more current fare into the curriculum. “If we studied something really modern like The Da Vinci Code – that would be really cool.”

Some Islamist movements have found their first flowering on university campuses. Such was the case with the Taliban, for instance. This doesn’t appear to have happened at Mosul University. Karam could think of only one student in his department who’d joined Isis. Of this his classmates learned only after the boy had died. The loss wasn’t widely mourned. He had been a blowhard and not much of a scholar.

“He used to be high all the time, actually,” Karam said. “He got killed at the end of 2014. When he got killed, we’re not supposed to be happy about people’s deaths, but we were.” He and the late jihadist had had one friend in common, an aspiring anarcho-nihilist. Now he had been a good student, Karam said. Very sharp. I pointed out Isis was nihilist in its way. Karam considered this. “Maybe, maybe. The nihilist boy, he was really sad when his friend the jihadist was killed.”

This is an edited extract from They Will Have to Die Now: Mosul and the Fall of the Caliphate by James Verini, published by Oneworld (£18.99). To order a copy go to guardianbookshop.com or call 0330 333 6846. Free UK p&p over £15, online orders only. Phone orders min p&p of £1.99