We unearthed thousands of internal documents that help explain how the Islamic State stayed in power so long.

SHARING THE RECORDS The New York Times is working to make the trove of ISIS documents publicly available to researchers, scholars, Iraqi officials and anyone else looking to better understand the Islamic State.

, a New York Times foreign correspondent, has covered ISIS since 2014. She has tracked the group's rise around the world from their encrypted, online chatrooms to on-the-ground reporting on four continents. Learn the backstory of her new audio series, Caliphate , in this Times Insider Q. and A.

On five trips to battle-scarred Iraq, journalists for The New York Times scoured old Islamic State offices, gathering thousands of files abandoned by the militants as their ‘caliphate’ crumbled.

MOSUL, Iraq — Weeks after the militants seized the city, as fighters roamed the streets and religious extremists rewrote the laws, an order rang out from the loudspeakers of local mosques.

Public servants, the speakers blared, were to report to their former offices.

To make sure every government worker got the message, the militants followed up with phone calls to supervisors. When one tried to beg off, citing a back injury, he was told: “If you don’t show up, we’ll come and break your back ourselves.”

The phone call reached Muhammad Nasser Hamoud, a 19-year veteran of the Iraqi Directorate of Agriculture, behind the locked gate of his home, where he was hiding with his family. Terrified but unsure what else to do, he and his colleagues trudged back to their six-story office complex decorated with posters of seed hybrids.

They arrived to find chairs lined up in neat rows, as if for a lecture.

The commander who strode in sat facing the room, his leg splayed out so that everyone could see the pistol holstered to his thigh. For a moment, the only sounds were the hurried prayers of the civil servants mumbling under their breath.

Their fears proved unfounded. Though he spoke in a menacing tone, the commander had a surprisingly tame request: Resume your jobs immediately, he told them. A sign-in sheet would be placed at the entrance to each department. Those who failed to show up would be punished.

Meetings like this one occurred throughout the territory controlled by the Islamic State in 2014. Soon municipal employees were back fixing potholes, painting crosswalks, repairing power lines and overseeing payroll.

“We had no choice but to go back to work,” said Mr. Hamoud. “We did the same job as before. Except we were now serving a terrorist group.”

The disheveled fighters who burst out of the desert more than three years ago founded a state that was acknowledged by no one except themselves. And yet for nearly three years, the Islamic State controlled a stretch of land that at one point was the size of Britain, with a population estimated at 12 million people. At its peak, it included a 100-mile coastline in Libya, a section of Nigeria’s lawless forests and a city in the Philippines, as well as colonies in at least 13 other countries. By far the largest city under their rule was Mosul.

How Far ISIS Spread Across Iraq and Syria and Where It’s Still Holding On Since declaring a caliphate in 2014, the Islamic State has controlled large swaths of territory in Iraq and Syria. But after the group retreated from Mosul and Raqqa in 2017, it lost nearly all of its territory. Persistent control Current control Short-lived Populated areas ISIS Control Key Qamishli Kobani TURKEY Dohuk Manbij Hasaka Tal Afar Sinjar Aleppo Idlib Mosul Raqqa Erbil Syria Iraq Sulaimaniya Deir al-Zour Hama Kirkuk Hawija Mayadeen Sukhna Homs Palmyra Lebanon Iran Tikrit Abu Kamal Qaim Ayn al-Fars Haditha Hit Baquba Damascus Falluja Ramadi Nawa Baghdad Rutba Sweida Jordan Dara’a Persistent control Short-lived Current control Populated areas ISIS Control Key TURKEY TURKEY Aleppo Mosul Raqqa Syria Syria Iraq Iraq Lebanon Lebanon Iran Iran Damascus Damascus Baghdad Baghdad Jordan Jordan ISIS Control Key Persistent control Short-lived Current ISIS control Populated areas TURKEY Aleppo Mosul Raqqa Syria Iraq Iran Lebanon Damascus Baghdad Jordan ISIS Control Key Persistent control Short-lived Current control Populated areas TURKEY Mosul Iran Raqqa Aleppo Syria Iraq Damascus Baghdad Rutba Jordan ISIS Control Key Persistent control Short-lived Current control Populated areas TURKEY Mosul Iran Raqqa Aleppo Syria Iraq Damascus Baghdad Rutba Jordan Sources: Conflict Monitor by IHS Markit (control areas); WorldPop (populated areas)

Note: Areas of control based on IHS reports from Sept. 21, 2015, to March 26, 2018.

Nearly all of that territory has now been lost, but what the militants left behind helps answer the troubling question of their longevity: How did a group whose spectacles of violence galvanized the world against it hold onto so much land for so long?

Part of the answer can be found in more than 15,000 pages of internal Islamic State documents I recovered during five trips to Iraq over more than a year.

The documents were pulled from the drawers of the desks behind which the militants once sat, from the shelves of their police stations, from the floors of their courts, from the lockers of their training camps and from the homes of their emirs, including this record detailing the jailing of a 14-year-old boy for goofing around during prayer.

B A D C This arrest record was for one of three boys who were A accused of fooling around during prayer. The ticket book was recovered in early 2017 north of Mosul in the town of Tel Kaif, in a house that ISIS had turned into a police station. B Ibrahim Muhammad Khalil, who was 14, was arrested at 3 p.m. on Dec. 21, 2015, by an ISIS police officer who booked him on charges of “laughing during prayer.” C “You are requested to transport the prisoner described above to … the Ministry of the Hisba, Nineveh Province, Tel Kaif Sector … as soon as possible, and hand over the prisoner and all the reports, observations and documents related to him as well as his belongings and personal possessions.” Reason for arrest: D “The propagation of virtue and prevention of vice.” This arrest record was for one of three boys who were A accused of fooling around during prayer. The ticket book was recovered in early 2017 north of Mosul in the town of Tel Kaif, in a house that ISIS had turned into a police station. B Ibrahim Muhammad Khalil, who was 14, was arrested at 3 p.m. on Dec. 21, 2015, by an ISIS police officer who booked him on charges of “laughing during prayer.” C “You are requested to transport the prisoner described above to … the Ministry of the Hisba, Nineveh Province, Tel Kaif Sector … as soon as possible, and hand over the prisoner and all the reports, observations and documents related to him as well as his belongings and personal possessions.” Reason for arrest: D “The propagation of virtue and prevention of vice.” B A D C Take a closer look at some of the documents here. B A D C This arrest record was for one of three boys who were A accused of fooling around during prayer. The ticket book was recovered in early 2017 north of Mosul in the town of Tel Kaif, in a house that ISIS had turned into a police station. B Ibrahim Muhammad Khalil, who was 14, was arrested at 3 p.m. on Dec. 21, 2015, by an ISIS police officer who booked him on charges of “laughing during prayer.” C “You are requested to transport the prisoner described above to … the Ministry of the Hisba, Nineveh Province, Tel Kaif Sector … as soon as possible, and hand over the prisoner and all the reports, observations and documents related to him as well as his belongings and personal possessions.” Reason for arrest: D “The propagation of virtue and prevention of vice.” B A D C This arrest record was for one of three boys who were A accused of fooling around during prayer. The ticket book was recovered in early 2017 north of Mosul in the town of Tel Kaif, in a house that ISIS had turned into a police station. B Ibrahim Muhammad Khalil, who was 14, was arrested at 3 p.m. on Dec. 21, 2015, by an ISIS police officer who booked him on charges of “laughing during prayer.” C “You are requested to transport the prisoner described above to … the Ministry of the Hisba, Nineveh Province, Tel Kaif Sector … as soon as possible, and hand over the prisoner and all the reports, observations and documents related to him as well as his belongings and personal possessions.” Reason for arrest: D “The propagation of virtue and prevention of vice.”

The New York Times worked with outside experts to verify their authenticity, and a team of journalists spent 15 months translating and analyzing them page by page.

Individually, each piece of paper documents a single, routine interaction: A land transfer between neighbors. The sale of a ton of wheat. A fine for improper dress.

But taken together, the documents in the trove reveal the inner workings of a complex system of government. They show that the group, if only for a finite amount of time, realized its dream: to establish its own state, a theocracy they considered a caliphate, run according to their strict interpretation of Islam.

The world knows the Islamic State for its brutality, but the militants did not rule by the sword alone. They wielded power through two complementary tools: brutality and bureaucracy.

ISIS built a state of administrative efficiency that collected taxes and picked up the garbage. It ran a marriage office that oversaw medical examinations to ensure that couples could have children. It issued birth certificates — printed on Islamic State stationery — to babies born under the caliphate’s black flag. It even ran its own D.M.V.

The documents and interviews with dozens of people who lived under their rule show that the group at times offered better services and proved itself more capable than the government it had replaced.

They also suggest that the militants learned from mistakes the United States made in 2003 after it invaded Iraq, including the decision to purge members of Saddam Hussein’s ruling party from their positions and bar them from future employment. That decree succeeded in erasing the Baathist state, but also gutted the country’s civil institutions, creating the power vacuum that groups like ISIS rushed to fill.

A little more than a decade later, after seizing huge tracts of Iraq and Syria, the militants tried a different tactic. They built their state on the back of the one that existed before, absorbing the administrative know-how of its hundreds of government cadres. An examination of how the group governed reveals a pattern of collaboration between the militants and the civilians under their yoke.

One of the keys to their success was their diversified revenue stream. The group drew its income from so many strands of the economy that airstrikes alone were not enough to cripple it.

Ledgers, receipt books and monthly budgets describe how the militants monetized every inch of territory they conquered, taxing every bushel of wheat, every liter of sheep’s milk and every watermelon sold at markets they controlled. From agriculture alone, they reaped hundreds of millions of dollars. Contrary to popular perception, the group was self-financed, not dependent on external donors.

More surprisingly, the documents provide further evidence that the tax revenue the Islamic State earned far outstripped income from oil sales. It was daily commerce and agriculture — not petroleum — that powered the economy of the caliphate.

The United States-led coalition, trying to eject the Islamic State from the region, tried in vain to strangle the group by bombing its oil installations. It’s much harder to bomb a barley field. It was not until last summer that the militants abandoned Mosul, after a battle so intense that it was compared to the worst combat of World War II.

While the militants’ state eventually crumbled, its blueprint remains for others to use.

“We dismiss the Islamic State as savage. It is savage. We dismiss it as barbaric. It is barbaric. But at the same time these people realized the need to maintain institutions,” said Fawaz A. Gerges, author of “ISIS: A History.”

“The Islamic State’s capacity to govern is really as dangerous as their combatants,” he said.

Land for the Taking

The day after the meeting, Mr. Hamoud, a Sunni, returned to work and found that his department was now staffed 100 percent by Sunnis, the sect of Islam practiced by the militants. The Shia and Christian colleagues who previously shared his office had all fled.

For a while, Mr. Hamoud and the employees he supervised at the agriculture department went on much as they had before. Even the stationery they used was the same, though they were instructed to use a marker to cover up the Iraqi government’s logo.

But the long-bearded men who now oversaw Mr. Hamoud’s department had come with a plan, and they slowly began to enact it.

For generations, jihadists had dreamed of establishing a caliphate. Osama bin Laden frequently spoke of it and his affiliates experimented with governing in the dunes of Mali, in the badlands of Yemen and in pockets of Iraq. Their goal was to recreate the society that existed over a millennium ago during the time of the Prophet Muhammad.

In Mosul, what had been called the Directorate of Agriculture was renamed Diwan al-Zera’a, which can be translated as the Ministry of Agriculture. The term “diwan” harks back to the seventh-century rule of one of the earliest caliphs.

ISIS printed new letterhead that showed it had branded at least 14 administrative offices with “diwan,” renaming familiar ones like education and health. Then it opened diwans for things that people had not heard of: something called the hisba, which they soon learned was the feared morality police; another diwan for the pillaging of antiquities; yet another dedicated to “war spoils.”

What began as a cosmetic change in Mr. Hamoud’s office soon turned into a wholesale transformation.

The militants sent female employees home for good and closed the day care center. They shuttered the office’s legal department, saying disputes would now be handled according to God’s law alone.

And they did away with one of the department’s daily duties — checking an apparatus, placed outside, to measure precipitation. Rain, they said, was a gift from Allah — and who were they to measure his gift?

Employees were also told they could no longer shave, and they had to make sure the leg of their trousers did not reach the ankle.

Glossy pamphlets, like the one below, pinpointed the spot on the calf where the hem of the garb worn by the companions of the Prophet around 1,400 years ago was said to have reached.

A B “The Sanctity of Men’s Garments” told men how to dress to follow the path laid by Prophet Muhammad. Recovered in early 2017 in Al-Araji village by a Times employee traveling with Iraqi troops. It was also published online. A “What Muslims are plagued with nowadays is that men wear their clothes long and women wear their clothes short!” B The picture pinpoints the spot on the calf where the hem should reach, citing an admonition from the Prophet to a follower whose garb was too long. “The Sanctity of Men’s Garments” told men how to dress to follow the path laid by Prophet Muhammad. Recovered in early 2017 in Al-Araji village by a Times employee traveling with Iraqi troops. It was also published online. B The picture pinpoints the spot on the calf where the hem should reach, citing an admonition from the Prophet to a follower whose garb was too long. A “What Muslims are plagued with nowadays is that men wear their clothes long and women wear their clothes short!” A B Take a closer look at some of the documents here. A B “The Sanctity of Men’s Garments” told men how to dress to follow the path laid by Prophet Muhammad. Recovered in early 2017 in Al-Araji village by a Times employee traveling with Iraqi troops. It was also published online. A “What Muslims are plagued with nowadays is that men wear their clothes long and women wear their clothes short!” B The picture pinpoints the spot on the calf where the hem should reach, citing an admonition from the Prophet to a follower whose garb was too long. A B “The Sanctity of Men’s Garments” told men how to dress to follow the path laid by Prophet Muhammad. Recovered in early 2017 in Al-Araji village by a Times employee traveling with Iraqi troops. It was also published online. A “What Muslims are plagued with nowadays is that men wear their clothes long and women wear their clothes short!” B The picture pinpoints the spot on the calf where the hem should reach, citing an admonition from the Prophet to a follower whose garb was too long.

Eventually, the 57-year-old Hamoud, who wears his hair in a comb-over and prides himself on his professional appearance, stopped buying razors. He took out the slacks he wore to work and asked his wife to trim off 5 centimeters.

But the biggest change came five months into the group’s rule, and it turned the hundreds of employees who had reluctantly returned to work into direct accomplices of the Islamic State. The change involved the very department Mr. Hamoud headed, which was responsible for renting government-owned land to farmers.

To increase revenue, the militants ordered the agriculture department to speed up the process for renting land, streamlining a weekslong application into something that could be accomplished in an afternoon.

That was just the beginning.

It was then that government workers got word that they should begin renting out property that had never belonged to the government. The instructions were laid out in a 27-page manual emblazoned with the phrase “The Caliphate on the Path of Prophecy.” The handbook outlined the group’s plans for seizing property from the religious groups it had expelled and using it as the seed capital of the caliphate.

“Confiscation,” the manual says, will be applied to the property of every single “Shia, apostate, Christian, Nusayri and Yazidi based on a lawful order issued directly by the Ministry of the Judiciary.”

Islamic State members are exclusively Sunni and see themselves as the only true believers. Mr. Hamoud’s office was instructed to make a comprehensive list of the properties owned by non-Sunnis — and to seize them for redistribution.

The confiscation didn’t stop at the land and homes of the families they chased out. An entire ministry was set up to collect and reallocate beds, tables, bookshelves — even the forks the militants took from the houses they seized. They called it the Ministry of War Spoils.

It was housed in a stone-faced building in western Mosul that was hit by an airstrike in the battle to retake the city. The ensuing fire consumed the structure and blackened its walls. But the charred shapes left behind still told a story. Each room served as a warehouse for ordinary household objects: kerosene heaters in one; cooking ranges in another; a jumble of air coolers and water tanks in yet another.

The few papers that did not burn up showed how objects seized from the religious groups they had chased out were offered as rewards to ISIS fighters.

“Please kindly approve the request of the family of the late Brother Durayd Salih Khalaf,” says one letter written on the letterhead of the Islamic State’s Prisoners and Martyrs Affairs Authority. The request was for a stove and a washing machine. A note scribbled at the bottom says: “To be provided with a plasma TV and stove only.”

Another application from the General Telecommunications Authority requested, among other things, clothes hangers.

A B C In January 2017, A the ISIS telecom department submitted a request form to the terrorist group’s agency in charge of handing out War Spoils. It received 16 household items. This document was recovered in a bombed-out building in western Mosul that had served as the headquarters of the Ministry of War Spoils. A spreadsheet lists the items the telecom department was seeking, including B eight plastic chairs, five curtains and one clothes hanger. C Each department had its own stamp, listing the name of the division and sometimes the name of the official in charge. In January 2017, A the ISIS telecom department submitted a request form to the terrorist group’s agency in charge of handing out War Spoils. It received 16 household items. This document was recovered in a bombed-out building in western Mosul that had served as the headquarters of the Ministry of War Spoils. An effusive greeting: “We are thankful for your cooperation with us, asking God, the Exalted, to elevate your stature and bless you with good judgment to serve Islam and Muslims.” (Not shown) A spreadsheet lists the items the telecom department was seeking, including B eight plastic chairs, five curtains and one clothes hanger. C Each department had its own stamp, listing the name of the division and sometimes the name of the official in charge. A B C Take a closer look at some of the documents here. In January 2017, A the ISIS telecom department submitted a request form to the terrorist group’s agency in charge of handing out War Spoils. It received 16 household items. This document was recovered in a bombed-out building in western Mosul that had served as the headquarters of the Ministry of War Spoils. A spreadsheet lists the items the telecom department was seeking, including B eight plastic chairs, five curtains and one clothes hanger. C Each department had its own stamp, listing the name of the division and sometimes the name of the official in charge. A B C A B C In January 2017, A the ISIS telecom department submitted a request form to the terrorist group’s agency in charge of handing out War Spoils. It received 16 household items. This document was recovered in a bombed-out building in western Mosul that had served as the headquarters of the Ministry of War Spoils. A spreadsheet lists the items the telecom department was seeking, including B eight plastic chairs, five curtains and one clothes hanger. C Each department had its own stamp, listing the name of the division and sometimes the name of the official in charge.

The Islamic State’s promise of taking care of its own, including free housing for foreign recruits, was one of the draws of the caliphate.

“I’m in Mosul and it’s really the top here,” Kahina el-Hadra, a young Frenchwoman who joined the group in 2015, wrote in an email that year to her secondary school teacher, according to a transcript contained in a report by the Paris Criminal Brigade, which was obtained by The Times.

“I have an apartment that is fully furnished,” Ms. Hadra gushed. “I pay no rent nor even electricity or water lol. It’s the good life!!! I didn’t buy so much as a single fork.”

When her concerned teacher wrote back that the apartment had probably been stolen from another family, she shot back: “Serves them right, dirty Shia!!!”

Ms. Hadra, according to police records, was the pregnant wife of one of the suicide bombers who blew himself up in the packed Bataclan concert hall during the Paris attacks of 2015.

The Paper Trail

I got into the habit of digging through the trash left behind by terrorists in 2013, when I was reporting on Al Qaeda in Mali. Locals pointed out buildings the group had occupied in the deserts of Timbuktu. Beneath overturned furniture and in abandoned filing cabinets, I found letters the militants had hand-carried across the dunes that spelled out their vision of jihad.

Those documents revealed the inner workings of Al Qaeda, and years later I wanted to investigate the Islamic State in the same way.

When the coalition forces moved to take Mosul back from the militants in late 2016, I rushed to Iraq. For three weeks, I tried — and failed — to find any documents. Day after day, my team negotiated access to buildings painted with the Islamic State logo, only to find desk drawers jutting out and hard drives ripped out.

Then, the day before my return flight, we met a man who remembered seeing stacks of paper inside the provincial headquarters of the Islamic State’s Ministry of Agriculture in a small village called Omar Khan, 25 miles southeast of the city. The next day we traveled to the town, no more than a speck on the map of the Nineveh Plains, and entered House No. 47.

My heart sank as we pushed open the door and saw the closets flung open — a clear sign that the place had already been cleared.

But on the way out, I stopped at what seemed to be an outhouse. When we opened the door, we saw piles of yellow folders cinched together with twine and stacked on the floor.

We pulled one out, laid it open in the sun — and there was the unmistakable black banner of the Islamic State, the flag they claim was flown by the Prophet himself.

Folder after folder, 273 in all, identified plots of land owned by farmers who belonged to one of the faiths banned by the group. Each yellow sleeve contained the handwritten request of a Sunni applying to confiscate the property.

B A A C This is one of 273 leases for land ISIS stole from members of religious groups it chased out. A This five-acre plot was rented to Ghanim Khalaf Ahmed for 100,000 dinars — roughly $83. The leases were found by Times reporters in the village of Omar Khan in northern Iraq in December 2016. A look at the fine print shows that the landowners this property was taken from were Shia. B Next to their names is their “status”: Rafidhis, a derogatory term for the Shia. C A tenant may not sublet the property; he must keep the property clean and in good condition; the property can only be modified after the approval of the Ministry of Agriculture. This is one of 273 leases for land ISIS stole from members of religious groups it chased out. A This five-acre plot was rented to Ghanim Khalaf Ahmed for 100,000 dinars — roughly $83. The leases were found by Times reporters in the village of Omar Khan in northern Iraq in December 2016. A look at the fine print shows that the landowners this property was taken from were Shia. B Next to their names is their “status”: Rafidhis, a derogatory term for the Shia. C A tenant may not sublet the property; he must keep the property clean and in good condition; the property can only be modified after the approval of the Ministry of Agriculture. B A A C Take a closer look at some of the documents here. B A A C This is one of 273 leases for land ISIS stole from members of religious groups it chased out. A This five-acre plot was rented to Ghanim Khalaf Ahmed for 100,000 dinars — roughly $83. The leases were found by Times reporters in the village of Omar Khan in northern Iraq in December 2016. A look at the fine print shows that the landowners this property was taken from were Shia. B Next to their names is their “status”: Rafidhis, a derogatory term for the Shia. C A tenant may not sublet the property; he must keep the property clean and in good condition; the property can only be modified after the approval of the Ministry of Agriculture. B A A C This is one of 273 leases for land ISIS stole from members of religious groups it chased out. A This five-acre plot was rented to Ghanim Khalaf Ahmed for 100,000 dinars — roughly $83. The leases were found by Times reporters in the village of Omar Khan in northern Iraq in December 2016. A look at the fine print shows that the landowners this property was taken from were Shia. B Next to their names is their “status”: Rafidhis, a derogatory term for the Shia. C A tenant may not sublet the property; he must keep the property clean and in good condition; the property can only be modified after the approval of the Ministry of Agriculture.

Doing so involved a step-by-step process, beginning with a report by a surveyor, who mapped the plot, noted important topographical features and researched the property’s ownership. Once it was determined that the land was owned by one of the targeted groups, it was classified as property of the Islamic State. Then a contract was drawn up spelling out that the tenant could neither sublet the land nor modify it without the group’s permission.

The outhouse discovery taught me to stay off the beaten track. I learned to read the landscape for clues, starting with باقية — “baqiya” — the first word of the Islamic State slogan. It can be translated as “will remain,” and marked the buildings the group occupied, invoking its claim that the Islamic State will endure.

Once we confirmed that a building had been occupied by the group, we lifted up the mattresses and pulled back the headboards of beds. We rifled through the closets, opened kitchen cupboards, followed the stairs to the roof and scanned the grounds.

The danger of land mines and booby-traps hung over our team. In one villa, we found a collection of records — but could search only one set of rooms after security forces discovered an unexploded bomb.

Because the buildings were near the front lines, Iraqi security forces nearly always accompanied our team. They led the way and gave permission to take the documents. In time, the troops escorting us became our sources and they, in turn, shared what they found, augmenting our cache by hundreds of records.

The Times asked six analysts to examine portions of the trove, including Aymenn Jawad al-Tamimi, who maintains his own archive of Islamic State documents and has written a primer on how to identify fraudulent ones; Mara Revkin, a Yale scholar who has made repeated trips to Mosul to study the group’s administration; and a team of analysts at West Point’s Combating Terrorism Center who analyzed the records found in Bin Laden’s hide-out in Pakistan.

They deemed the records to be original, based on the markings, logos and stamps, as well as the names of government offices. The terminology and design were consistent with those found on documents issued by the group in other parts of the caliphate, including as far afield as Libya.

As lease after lease was translated back in New York, the same signature inked at the bottom of numerous contracts kept reappearing: “Chief Technical Supervisor, Mahmoud Ismael Salim, Supervisor of Land.”

On my first trip back to Iraq, I showed the leases to a local police officer. He recognized the angular signature and offered to escort me to the home of the ISIS bureaucrat.

The officer shrugged when asked why a man who had taken part in the group’s organized land theft had not been arrested. His men were overwhelmed investigating those who had fought and killed on behalf of the terrorist group, he said. They didn’t have time to also go after the hundreds of civil servants who had worked in the Islamic State’s administration.

Hours later, the man whose signature appeared on the lease for farmland seized from a Christian priest, on the contract for the orchards taken from a monastery, and on the deed for land stolen from a Shia family allowed us into his modest home.

The only decoration in his living room was a broken clock whose hand trembled between 10:43 and 10:44.

A stooped man with thick glasses, the 63-year-old Salim was visibly nervous. He explained that he had spent years overseeing the provincial office of the government of Iraq’s Directorate of Agriculture, where he reported to Mr. Hamoud, whom we contacted for the first time a few days later.

Mr. Salim acknowledged that it was his signature on the leases. But speaking haltingly, he claimed to have been forcibly conscripted into the bureaucracy of the terrorist state.

“They took our files and started going through them, searching which of the properties belong to Shia, which of them belong to apostates, which of them are people who had left the caliphate,” he said.

He described informants phoning in the addresses of Shias and Christians.

Sunnis who were too poor to pay the rent upfront were offered a sharecropping agreement with the Islamic State, allowing them to take possession of the stolen land in return for one-third of the future harvest.

On busy days, a line snaked around his office building, made up of Sunni farmers, many of them resentful of their treatment at the hands of a Shia-led Iraqi government. In the same compound where we found the stacks of yellow folders, Mr. Salim received men he knew, whose children had played with his. They came to steal the land of other men they all knew — whose children had also grown up alongside theirs.

With the stroke of his pen, farmers lost their ancestors’ cropland, their sons were robbed of their inheritance and the wealth of entire families, built up over generations, was wiped out.

“These are relationships we built over decades, from the time of my father, and my father’s father,” Mr. Salim said, pleading for understanding. “These were my brothers, but we were forced to do it.”

A Clean Sweep

As 2014 blurred into 2015 and Mr. Hamoud and his colleagues helped keep the machinery of government running, Islamic State soldiers set out to remake every aspect of life in the city — starting with the role of women.

Billboards went up showing an image of a woman fully veiled. The militants commandeered a textile factory, which began manufacturing bales of regulation-length female clothing. Soon thousands of niqab sets were delivered to the market, and women who didn’t cover up began to be fined.

Mr. Hamoud, who is known as “Abu Sara,” or Father of Sara, gave in and bought a niqab for his daughter.

As he walked to and from work, Mr. Hamoud began taking side streets to dodge the frequent executions that were being carried out in traffic circles and public squares. In one, a teenage girl accused of adultery was dragged out of a minivan and forced to her knees. Then a stone slab was dropped onto her head. On a bridge, the bodies of people accused of being spies swung from the railing.

But on the same thoroughfares, Mr. Hamoud noticed something that filled him with shame: The streets were visibly cleaner than they had been when the Iraqi government was in charge.

Omar Bilal Younes, a 42-year-old truck driver whose occupation allowed him to crisscross the caliphate, noticed the same improvement. “Garbage collection was No. 1 under ISIS,” he said, flashing a thumbs-up sign.

The street sweepers hadn’t changed. What had was that the militants imposed a discipline that had been lacking, said a half-dozen sanitation employees who worked under ISIS and who were interviewed in three towns after the group was forced out.

“The only thing I could do during the time of government rule is to give a worker a one-day suspension without pay,” said Salim Ali Sultan, who oversaw garbage collection both for the Iraqi government and later for the Islamic State in the northern Iraqi town of Tel Kaif. “Under ISIS, they could be imprisoned.”

Residents also said that their taps were less likely to run dry, the sewers less likely to overflow and potholes fixed more quickly under the militants, even though there were now near-daily airstrikes.

Then one day, residents of Mosul saw earthmovers heading toward a neighborhood called the Industrial Area in the eastern half of the city. Laborers were seen paving a new blacktop road that would eventually run for roughly one mile, connecting two areas of the city and reducing congestion.

The new highway was called “Caliphate Way.”

The new government did not concern itself only with administrative matters. For morality, as for everything else, there was a bureaucracy.

Citizens stopped in the street by the hisba, the morality police, and accused of an offense were ordered to hand over their IDs in return for a “confiscation receipt.” The ID was taken to the group’s office, where residents were forced to appear and face judgment. Religious specialists weighed the crime, filling out a form.

Afterward, the offender was made to sign another form: “I, the undersigned, pledge not to cut or trim my beard again,” said one. “If I do that again, I will be subject to all kinds of punishments that the Hisba Center may take against me.”

The zeal with which the Islamic State policed the population is reflected in the 87 prison transfer records they abandoned in one of their police stations. Citizens were thrown into jail for a litany of obscure crimes, including eyebrow plucking, inappropriate haircuts, raising pigeons, playing dominoes, playing cards, playing music and smoking the hookah.

In early 2016, Mr. Hamoud’s daughter Sara ran out for a quick errand without covering her eyes.

She was spotted by an officer from the morality police. Before she could explain, he smashed his fist into her eye.

From then on, her father forbade her to leave the house, except to drive to the hospital for the appointments that followed the assault, which left her with vision loss, the family said.

With change sweeping the region, residents were forced to make fraught choices, among them: Stay or leave, rebel or accommodate.

Mr. Hamoud decided to try to escape. He and his eldest son, 28-year-old Omar, had set aside over $30,000 to buy a new home. The morning of their planned departure, Omar withdrew all but around $1,000 from the bank account.

Not even two hours later, a unit of masked fighters banged down the family’s front door. One of them was holding the bank slip Omar had signed.

“Try this again and we’ll kill every last one of you,” the militants warned.

The Money Machine

On the western banks of the Tigris River, in a pulverized building, I found an abandoned briefcase.

The documents that spilled out revealed that the briefcase belonged to Yasir Issa Hassan, a young professional whose photo identification shows a balding man with a large, aquiline nose. He was the administrator of the Trade Division inside the Islamic State Ministry of Agriculture.

The group’s outsize ambitions and its robust bureaucracy hinged on its ability to generate funds. Bulging with accounting forms, budget projections and receipts, as well as two CD-ROMs containing spreadsheets, the briefcase shed light on the scope of the organization’s revenue machine and offered a blueprint for how it worked.

The financial reports tallied over $19 million in transactions involving agriculture alone.

The documents describe how it made money at every step in the supply chain: Before a single seed of grain, for example, was sown, the group collected rent for the fields it had confiscated. Then, when the crops were ready to be threshed, it collected a harvest tax.

Caliphate Sign up to receive weekly dispatches from Rukmini Callimachi and learn when new episodes are live. Times subscribers will get early access to new episodes. You’ll receive Top Stories notifications after the series ends.

It did not stop there.

The trucks that transported the grain paid highway tolls. The grain was stored in silos, which the militants controlled, and they made money when the grain was sold to mills, which they also controlled. The mills ground the grain into flour, which the group sold to traders.

Then the bags of flour were loaded onto trucks, which traversed the caliphate, paying more tolls. It was sold to supermarkets and shops, which were also taxed. So were the consumers who bought the finished product.

In a single 24-hour period in 2015, one of the spreadsheets in the briefcase shows, the Islamic State collected $1.9 million from the sale of barley and wheat.

Another table shows that the militants earned over $3 million in three months from gross flour sales in just three locations in Mosul.

The organization appeared intent on making money off every last grain — even crops that were damaged.

On just one day, according to another statement, it took in over $14,000 from wheat described as having been scorched in a bombing, and $2,300 from the sale of spoiled lentils and chickpeas. It also took in over $23,000 from grain that had been scraped off the bottom of a tank, according to one spreadsheet.

The Islamic State’s tax arm reached into every facet of life in Mosul. Households in Iraq were taxed 2,000 dinars per month (less than $2) for garbage collection, 10,000 dinars (about $8) for each 10 amperes of electricity, and another 10,000 for municipal water.

Businesses wishing to install a landline paid a 15,000-dinar (about $12) installation fee to the group’s telecommunications office, followed by a 5,000-dinar monthly maintenance fee.

Municipal offices charged for marriage licenses and birth certificates.

C B B A This birth certificate is for a girl named Shehed. A She weighed 4 kilograms when she was born on Aug. 26, 2016, in an administrative area created by ISIS called Al-Jazeera province. The paper was recovered by Times journalists in Tal Abta, a village in northern Iraq, in July 2017 in a building used by ISIS fighters. Shehed was born at home to B Wadha Mansour Ubaid, 20, and Mahmud Muhammad Mousa, a 35-year-old laborer. There was no doctor, nurse or certified midwife at the birth. ISIS issued numbered birth certificates on stationery that read, C “The Islamic State, Ministry of Health” to children born under their black flag. This birth certificate is for a girl named Shehed. A She weighed 4 kilograms when she was born on Aug. 26, 2016, in an administrative area created by ISIS called Al-Jazeera province. The paper was recovered by Times journalists in Tal Abta, a village in northern Iraq, in July 2017 in a building used by ISIS fighters. Shehed was born at home to B Wadha Mansour Ubaid, 20, and Mahmud Muhammad Mousa, a 35-year-old laborer. There was no doctor, nurse or certified midwife at the birth. ISIS issued numbered birth certificates on stationery that read, C “The Islamic State, Ministry of Health” to children born under their black flag. C B A Take a closer look at some of the documents here. C B A This birth certificate is for a girl named Shehed. A She weighed 4 kilograms when she was born on Aug. 26, 2016, in an administrative area created by ISIS called Al-Jazeera province. The paper was recovered by Times journalists in Tal Abta, a village in northern Iraq, in July 2017 in a building used by ISIS fighters. Shehed was born at home to B Wadha Mansour Ubaid, 20, and Mahmud Muhammad Mousa, a 35-year-old laborer. There was no doctor, nurse or certified midwife at the birth. ISIS issued numbered birth certificates on stationery that read, C “The Islamic State, Ministry of Health” to children born under their black flag. C B A This birth certificate is for a girl named Shehed. A She weighed 4 kilograms when she was born on Aug. 26, 2016, in an administrative area created by ISIS called Al-Jazeera province. The paper was recovered by Times journalists in Tal Abta, a village in northern Iraq, in July 2017 in a building used by ISIS fighters. Shehed was born at home to B Wadha Mansour Ubaid, 20, and Mahmud Muhammad Mousa, a 35-year-old laborer. There was no doctor, nurse or certified midwife at the birth. ISIS issued numbered birth certificates on stationery that read, C “The Islamic State, Ministry of Health” to children born under their black flag.

But perhaps the most lucrative tax was a religious tax known as zakat, which is considered one of the five pillars of Islam. It is calculated at 2.5 percent of an individual’s assets, and up to 10 percent for agricultural production, according to Ms. Revkin, the Yale researcher. While some of these fees had been charged by the Iraqi and Syrian governments, the mandatory asset tax was a new development.

Ordinarily in Islamic practice, the zakat is a tithe used to help the poor. In the Islamic State’s interpretation, an act of charity became a mandatory payment, and while some of the funds collected were used to help needy families, the Ministry of Zakat and Charities acted more like a version of the Internal Revenue Service.

Most accounts of how the Islamic State became the richest terrorist group in the world focus on its black-market oil sales, which at one point brought in as much as $2 million per week, according to some estimates. Yet records recovered in Syria by Mr. Tamimi and analyzed by Ms. Revkin show that the ratio of money earned from taxes versus oil stood at 6:1.

Despite hundreds of airstrikes that left the caliphate pocked with craters, the group’s economy continued to function, fed by streams of revenue that could not be bombed under international norms: the civilians under their rule, their commercial activity and the dirt under their feet.

According to estimates from the Food and Agriculture Organization of the United Nations, the land that the militants seized was Iraq’s most fertile, and at the group’s height, the fields that were harvested accounted for 40 percent of the country’s annual wheat production and more than half of its barley crop. In Syria, the group at one point controlled as much as 80 percent of the country’s cotton crop, according to a study by the Paris-based Center for the Analysis of Terrorism.

It all added up to astonishing sums, as much as $800 million in annual tax revenue, according to the study.

Still, the group’s ambition of running a state meant it also had large bills.

On a single day in the summer of 2016, the owner of the briefcase handed over $150,000 to one of the group’s accountants to pay for the transport of wheat from one town to another, according to one financial report.

In a two-week period the same year, he paid over $16,000 to the Islamic State trade division in the Dijlah district and $14,000 to the one in Kirkuk. He gave an $8,400 cash advance to the group’s Hawija office, $16,800 to the land department and $8,400 to the Islamic State province straddling the Euphrates River.

Tax collection continued until the very end. At least 100 documents labeled “Daily Gross Revenue” that showed incoming cash were dated November 2016, a month after the start of the coalition’s push to take back the city.

Even as tanks were rolling in and taking surrounding neighborhoods, the trade division continued to make money, pocketing $70,000 in a single sale.

After ISIS

One day in late 2016, a flier decorated with the Iraqi flag floated down onto the Hamoud family’s home.

The agricultural department official and his extended family were hunkered down inside the living room, sitting elbow-to-elbow on an L-shaped couch, he recalls. By then, the militants had banned both cellphones and satellite dishes. They were cut off from the world.

The flier was one of millions dropped over Mosul warning the population to take cover. The military assault was about to begin.

“Could this really be happening?” Mr. Hamoud wondered. Then he used a lighter to incinerate the flier.

The fighters whose plans of building a state had been met with ridicule proved surprisingly good at it. It took nine months to wrest Mosul from the militants’ grip, a slog that one senior American general said was the most difficult battle he had witnessed in 35 years.

Since then, the militants have lost all but 3 percent of the territory in Iraq and Syria they once held. But they clung so tightly to their caliphate that block after city block was leveled during the battle to take back cities and towns. Thousands of people have lost their homes. New mass graves are being discovered every month. One of them contains the remains of four of Mr. Hamoud’s cousins.

His daughter Sara now wears thick glasses to correct her vision, which has been blurry since the day she was punched by the hisba. Even through her compromised eyesight, she can see the mountain of trash rising in the empty lot across from her family’s home.

Few have anything good to say about their old rulers — unless prodded to talk about the services they provided.

“We have to be honest,” Mr. Hamoud said. “It was much cleaner under ISIS.”

Though the militants are gone, reminders of the Islamic State and their particular style of governance remain.

In the northern town of Tel Kaif, for example, residents recall how the militants conscripted a committee of electrical engineers to fix an overloaded power grid. They installed new circuit breakers, and for the first time, residents who had been accustomed to at most six hours of electricity a day could now reliably turn on lights.

In early 2017, Iraqi soldiers reclaimed the town, and were welcomed as heroes. But then they disconnected the Islamic State circuit breakers — and the power failures resumed.

“If the government was to go back to the system that ISIS put in place, we would go so far as to kiss their foreheads,” Mr. Younes, the truck driver, said at the time.

Within a few months, the government did just that.

The irony that it had taken a terrorist group to fix one of the town’s longstanding grievances was not lost on its citizens.

“Although they were not recognized as a state or a country,” said one shopkeeper, Ahmed Ramzi Salim, “they acted like one.”