In February 2009, I was at a motor park in Maraba, a satellite of the Nigerian capital Abuja, looking for motorcyclists wearing dried vegetables on their heads. The Nigerian Police Force had recently tightened laws requiring drivers and passengers of motorcycles to wear helmets. In the case of motorcycle taxis – known as achabas in northern Nigeria – drivers would now have to provide helmets for their passengers. There was an uproar. Everyone knew that taking a trip on an achaba could be a dangerous thing; the drivers had a reputation for recklessness. But many Nigerians did not like the new rules.

Above all, the law gave the police an opportunity for extortion. One motorcycle taxi driver told me it was going to cost him 10,000 naira (around £40) to buy two helmets. As he made between 300 and 400 naira per day (less than £2), there was no way he could afford to obey the new law. Everyone knew what would happen. The police would set up flying checkpoints, near markets, motor parks and busy thoroughfares. They would swoop down on motorcyclists, flailing sticks and canes as the riders madly accelerated out of their traps.

Join us or die: the birth of Boko Haram Read more

People who drive achabas are close to the bottom of society. They are men (and only men) without much formal education, often without any other marketable skill. Many sleep rough, under bridges or awnings, some sleep on their motorcycles, guarding their source of income. Their passengers are also mostly poor. The vast number of achabas on the roads is a symptom of Nigeria’s economic problems. The new helmet law was, in the minds of most, just another squeeze on people already in perilous circumstances.

When the regulations came into force, something strange happened. As hardly anyone had helmets to wear, achaba drivers took to the streets in all manner of improvised headgear. There were pictures in the press of people wearing paint cans and buckets; but best of all were riders wearing hollowed-out watermelons and calabash bowls – rustic utensils made out of dried gourds that, before the advent of plastic, were ubiquitous as water vessels.

These achaba drivers had stood up against barely disguised official extortion. Their resistance was characteristically subversive. But most Nigerians simply added the new legislation to the long list of things that made their lives difficult – then they prayed, hoped the police would quickly lose interest and carried on as normal.

In one part of the country, however, this cat-and-mouse game between police and Nigerian motorists would have much more serious consequences. In Maiduguri, the capital of the north-eastern Borno state, enforcement of the helmet law caused an incident that would spark a violent conflict between the police and members of a radical Islamist sect that was then unknown to the world. This, in turn, would pitch Nigeria into war.

Two years later, I watched as a slight young man entered the office of Maiduguri’s Special Armed Robbery Squad. The building is known locally as “The Crack”, ostensibly because it houses the elite police force. It is also a place from where, once a person falls in, they might never emerge.

The young man, whose name was Mohammed Zakariyya, was led inside by two plainclothes officers. He had been arrested a few days before, after the car he was driving was stopped at a police checkpoint. He was thin and looked to be barely more than a teenager. His long pink, kaftan-like shirt was dirty and flecked with small spots of dried blood.

“They discovered the weapons we had hidden underneath the seat,” Zakariyya told me and my fellow BBC journalist, Abdullahi Kaura Abubakar. When his companion was ordered out of the vehicle to let the police search it, he tried to drive off. The Police Mobile Force officers opened fire, killing him. (The red hatchback, now full of holes, sat in the yard of the Borno police headquarters.)

Zakariyya said that he had been on three arms smuggling missions. Each time, he and his accomplices drove 120km out of Maiduguri to meet a man who ferried weapons in a canoe downriver from the mountainous border with Cameroon. Each time, he brought them half-a-dozen AK-47s and a handful of boxes of ammunition. They loaded the car, then Zakariyya drove it through Maiduguri to a large house in the suburbs of Damaturu, the capital of the neighbouring state of Yobe.

The men he was working for had approached Zakariyya at the end of 2010 while he was selling shoes and phone chargers. “They used to preach in the open, so everyone was aware of who they were,” he said.

In one part of the country this cat-and-mouse game between police and Nigerian motorists would have serious consequences

“They” were members of the hardline Islamist sect that had established itself between 2005 and 2009 at a compound in Maiduguri’s Railway district. Known as Boko Haram, which translates as “Western education is forbidden”, the group had gradually brought more and more people under its influence.

The man we had come to Maiduguri to speak with was a member who called himself Abu Dujana – his nom de guerre was taken from one of the companions of the prophet Muhammad. He described the atmosphere of the sect’s Maiduguri headquarters in cult-like terms. The pace of life inside was dictated by the charismatic leader Mohammed Yusuf, who set and enforced strict standards of religious practice. “Yes, I lived there,” Abu Dujana said proudly. “There wasn’t a mosque like this in the whole of the country, where you could go and attain as much knowledge.”

On 20 February 2009, members of the sect were travelling to a funeral in a large group. The convoy was made up of many motorbikes, and the police stopped them. The police were part of a state-wide task force, named Operation Flush and set up in 2005 to combat political thugs who had run amok in elections two years before. The dispute between the group and the police about their refusal to wear helmets became heated. Some reports of the exchange say that the police shot first, others that a member of the group disarmed a policeman and tried to use his weapon on the other police officers. In any case, the police opened fire, and several people in the travelling funeral party were killed and wounded.

This was not the first time that Operation Flush had crossed paths with Boko Haram, and the group’s leadership had already concluded that the purpose of the Joint Task Force was to harass them directly. In the weeks following this encounter, Yusuf made a series of speeches, circulated widely on tapes and DVDs and over Bluetooth connections, calling on Muslims to prepare to “come to Jihad”. This, he said, included “material preparation such as learning shooting, buying rifles and bombs, as well as training the Islamic Soldiers to fight the infidels. You should sacrifice your souls, your homes, your cars and your motorcycles for the sake of Allah.”

Yusuf also had a large farm in Bauchi state, which he used as a base. The state government responded to these speeches by ordering the police to raid the farm, capturing hundreds of Boko Haram members and killing several more. The police laid siege to the sect’s headquarters in the Ibn Taymiyyah mosque compound in Maiduguri. “They did not engage us fully, but tried to provoke us, driving along the side of the compound in a jeep,” Dujana told me. “We waited until we had our chance and then we took it.”

Nigerian army storms Islamist sect's base Read more

When they saw the state’s forces had pulled back and commenced shooting at them from a distance, the men inside armed themselves and broke out of the compound. Dujana said they split into groups – he led one detachment, which roamed the city looking for military and police units to attack. For four days Boko Haram rampaged through the streets of Maiduguri. As well as killing police and soldiers, they slaughtered scores of civilians who were caught out in the open, slitting their throats like animals.

As the authorities re-established control of the town, Mohammed Yusuf was captured by the military. He was interrogated in front of journalists who filmed it with their phones. He was then handed over to the police. Within minutes, Yusuf was dead – shot, the police said, while trying to escape. Nobody believed this. Yusuf’s bullet-ridden body was then displayed to journalists, who took pictures.

Facebook Twitter Pinterest The Borno state task force, Operation Flush, stands guard during a religious celebration in Maiduguri, in 2013. Photograph: Sunday Alamba/AP

This was just the beginning of a tide of violence that has left thousands of people dead and at least 1.5 million people displaced from their homes. Seven years after Yusuf’s killing, the war between Boko Haram and the Nigerian state has changed and developed. From late 2014 to early 2015, the sect controlled an estimated 70% of Borno state – the authorities, meanwhile, seemed incapable of dislodging it.

After his election in 2015, President Muhammadu Buhari of the All Progressives Congress party tried to reinvigorate the military leadership by replacing a number of top generals. This, he hoped, would bolster the state’s response to Boko Haram. By August 2015, the military had reversed many of the group’s gains and pushed it back to more remote areas. But the war is by no means finished.

In November, during attacks 48 hours apart, suicide bombers killed scores in the eastern city of Yola and Kano in the north, targets that lie hundreds of miles apart. These attacks show the extent of the group’s reach, even outside the area it once controlled. There have been continual, under-reported, skirmishes in the border regions of north-east Nigeria. Just last Friday, on 29 January, the group launched an attack on Dalori, a small town close to Maiduguri. As many as 80 people were killed. Witnesses said they heard the screams of dying children as their houses burned down around them. These attacks are in spite of Buhari’s announcement in December that the war was “technically over”.

Muhammadu Buhari: reformed dictator returns to power in democratic Nigeria Read more

Yusuf’s group did not appear out of nowhere. Even before the open war between Boko Haram and the state, it had been growing. Among its ranks were people from all levels of society, from street kids and traders, to disaffected students and wealthy businessmen.

Many of the young men and women came from the University of Maiduguri, where the elite of the 1990s sent their children to be educated. The institution was famed for the hedonism of its students, who indulged in ritual displays of wealth. The young sons of the elite would compete to be “King of Campus”: the winner racked up the highest expense on parties. The “naira spray” was a particularly fashionable form of celebration, much seen during the oil boom of the 1970s: to honour a talented musician, dancer or a pretty girl, one of these wealthy young men would scatter a rain of currency that the object of their approval would then pick up off the floor.

To some, this fetishisation of money was an example of the injustice and immorality at the heart of the state. Disaffected students and university dropouts gravitated towards the youth wing of a Salafi group at a mosque in Maiduguri. Among them were the nephew of the governor of Yobe state, the son of the state secretary of Borno and five sons of a prominent businessman who had made his money through state contracts. These young men were drawn to the Salafists, who preached that such spiritual corruption was the cause of Borno’s ills. Many of them burned their university certificates when they joined.

One man saw the potential of these young radicals, born into privilege. His name was Mohammed Yusuf.

Yusuf had been travelling around the north-east, preaching, making contacts and winning a following since the mid-1990s. He was a charismatic speaker who had no trouble attracting an audience. His radical ideas about the infidel state of Nigeria resonated with many people. He gave fiery orations at mosques and debated with other Islamic scholars on local television and radio.

According to his supporters, Yusuf was one of thousands of Almajiri children – religious students who beg on the streets for a living. But by the early 2000s he had found a place as a leader of the youth wing of a Salafist group at Maiduguri’s popular Alhaji Muhammadu Ndimi mosque.

Yusuf told his followers that Muslims who participated in any form of democratic system were apostates and should be killed by the faithful. The wellspring of corruption, he concluded, was the education system put in place during and after colonial rule by Christian Britain. He preached in busy towns on market days (rather than on Fridays, a breach of tradition that angered the Islamic authorities), where he picked up many followers.

In the years before the 2009 uprising, observers were shocked at the extent of Yusuf’s influence, which spread deep into the border regions. Anthropologist Gerhard Müller-Kosack spent years studying a village in the Mandara mountains, near the border with Cameroon. He said the village changed “virtually overnight”. When he visited for the last time in 2008, what surprised him most were the women: “Suddenly they were there in the full covering. It was the women at the forefront of the change.” During their years in the village, Müller-Kosack and his wife had started a school. He had collected donations from friends and colleagues to buy textbooks. The last time he visited, he found the school abandoned: “All the books had been burned – the young women, it was they who made a pile of them and burned them in front of the school.”

Facebook Twitter Pinterest A burnt-out police patrol truck after a Boko Haram bomb attack in Damaturu, in 2011. Photograph: Pius Utomi Ekpei/AFP/Getty Images

From the very beginning, Yusuf was preparing his followers for conflict. Among the first generation of supporters were many ideologues willing to unleash violence on the state, innocent civilians, the Muslim establishment and anyone they declared to be unbelievers. They formed a “counter elite”, united by resentment of years of secular rule in Nigeria. These men dreamed of a sharia wonderland, and believed it would come to Nigeria through unremitting bloodshed.

Before the 2009 uprising, the Salafists associated with the Ndimi mosque had already made one disastrous attempt at creating an Islamic state. In 2003, a man named Muhammad Ali, who had tired of Yusuf’s slow approach to building a movement, led a band of 200 young men and women out into the wilderness to start society anew. They ended up in the borderlands of Yobe state, near the dry river bed between Nigeria and the Republic of Niger, at a place called Kanamma. They were determined to shun the corrupt world and create a new land of Islamic purity.

This group of aggressive, iconoclastic city-dwellers soon came into conflict with the people who already lived in the place they tried to settle. Indeed, conflict was what they sought. They dug defensive preparations in a wooded grove near a water source. They raided local police stations and government buildings to get weapons, and to provoke a reaction, which duly came. After a brief siege, the military overran and destroyed the camp. The group’s members were mostly wiped out. A few survivors escaped north, over the border to Niger, where some can still be found. Others slunk back to Maiduguri.

The military crackdown attracted international attention because the group dubbed itself the “Nigerian Taliban”. But, at the time, the US embassy concluded that it had no links to al-Qaida.

Yusuf had not joined the Kanamma uprising. Still, after the group was crushed, he went into self-imposed exile in Saudi Arabia to escape accusations that he had anything to do with it. It is thought that, while he was there, he made links with like-minded Salafi preachers and secured their support. But after a year, he was back in Maiduguri.

On his return, in 2005, Yusuf began to rebuild his own community, establishing the Ibn Taymiyyah mosque and compound in the Railway district of Maiduguri on land bought with the help of his father-in-law. This location, in the heart of the state capital, was key to the group’s new incarnation. By embedding themselves in the town rather than the wilderness, the group had many more avenues for recruitment and funding. The population of Maiduguri has risen dramatically in recent years. Desertification across the north of Borno state has, over the last decade, destroyed farmland and sparked an exodus to the city. The academic Mohammed Kabir Isa of Ahmadu Bello University Zaria says: “When they come to the city in search of a livelihood, the bubble bursts, and they realise there’s nothing there. That’s when they become easy prey for militant organisations.”

Nigeria: Religious tensions put taxi drivers in Jos at a deadly crossroads Read more

By the end of 2008, the group was operating like a state within a state; it had its own institutions, including a shura council to make decisions and a religious police force to enforce discipline. It had a rudimentary welfare system, offered jobs working the land it had acquired in Bauchi and even gave microfinance loans to members to start their own projects. Many used the money to buy motorcycles and worked as achaba drivers. The group also arranged marriages between members, which many of the poorest could not afford in normal life. Rather than sticking out as rebels, Yusuf and his followers could blend in with ordinary people.

Yusuf was also comfortable moving between the different layers of Maiduguri society. The city has always been an important trading post for dealers in goods of all kinds – legal and otherwise. Its proximity to the borders of three countries – Cameroon, Chad, Niger – makes it an ideal hub for speculation in commodities such as fertiliser, kerosene, diesel and petrol. Maiduguri’s trading elite have made a lot of money. Some of them gravitated to Yusuf’s Salafist group in the belief that they should atone for their prosperity.

The Ibn Taymiyyah mosque had been allowed to function thanks to a deal that Yusuf had struck with the government. The agreement between the state deputy governor and Yusuf had been brokered in Saudi Arabia by a leading Salafist sheikh. Yusuf promised that he had nothing to do with the separatist group in Kanamma and would never again preach violent jihad. But in the following years, he ignored this pledge and was picked up by the security services several times, only to be swiftly released. The journalist who first reported on Yusuf’s sect believes that – at least at this early stage – its leader enjoyed high-level backing from the governor of Borno, Ali Modu Sherif.

Ahmed Salkida, a reporter for the Daily Trust, one of the few Nigerian papers that focus on the north, wrote extensively about the group in the years before 2009. He says that despite his professed loathing of politics, Yusuf made alliances and found common ground with Sherif. Both men had much to gain from cooperation. Yusuf wanted the guarantees of a stronger sharia, a commitment to a strict line on God’s divine law; Sherif wanted to be re-elected. Sherif denies any such arrangement or involvement with the sect.

In public, the two men had an antagonistic relationship. Yusuf had called Sherif an “infidel” and demanded his death. Sherif, however, knew that it would have been unwise to fight Yusuf. Instead, he courted him, providing a lucrative position in the state religious affairs ministry to one of Boko Haram’s most zealous members, a man named Buji Foi.

Questions still hang over the speed with which Yusuf was dispatched, and who exactly was served by his silencing

Salkida told me that until the final days before the uprising, Yusuf still believed that a deal could be done with the state, and that Sherif would come around to Boko Haram’s uncompromising position. But by that stage Sherif had been backed into a corner. He could no longer protect Yusuf, who was handed over to the police, and quickly executed. Questions still hang over the speed with which Yusuf was dispatched, and who exactly was served by his silencing.

After Yusuf’s death, his lieutenants went into hiding, but they were sustained by their loyalty to his vision. Under the leadership of Abubakar Shekau, who had been Yusuf’s second-in-command, Boko Haram’s priority was revenge. The group’s first targets were the police, who were attacked at their own checkpoints and robbed of their weapons. Higher-ranking officers were assassinated in their homes, as were local politicians and traditional rulers. After the uprising, the authorities had demanded that traditional leaders help them identify members of Boko Haram, who were then summarily executed, and their property given to the informants as reward. Now the group came back to murder those who had betrayed them, robbing them of what they called the “spoils of war” – wealth that belonged to the jihadi fighters.

In June 2011, under cover of darkness, Mohammed Manga, a 35-year-old commercial driver, set out from a camp near Maiduguri for the capital. In his car was an explosive device prepared by either al-Qaida in the Islamic Mahgreb, which was then in camps in the Sahara, or al-Shabaab in Somalia. He drove into the police headquarters, past the sentries and up to the front door, in the middle of a crowd. When he detonated the bomb, five were killed and more than 100 injured.

A spokesman for Boko Haram said that Manga had left his widow and five children a considerable inheritance. A photograph sent to journalists showed him smiling and waving as he got into the car, holding an AK-47. “He was calm and never showed fear,” the group’s spokesman told Salkida. He added that everyone was envious of Manga, “wishing it was their chance to act and gain entry into paradise”.

Boko Haram followed up this mission a few weeks later, in August 2011, by detonating a car packed with explosives in the driveway of the United Nations building in Abuja. At least 21 people were killed and scores wounded.

Facebook Twitter Pinterest Abubakar Shekau, the leader of Boko Haram in 2014. Photograph: -/AFP/Getty Images

The group unleashed a bombing campaign in Maiduguri, Jos, Kaduna and the capital, and devastating coordinated strikes against the security services in Kano. It attacked churches, universities and schools, bus stations and markets, killing thousands. Within a few years, between 2011 and 2014, Boko Haram had gone from the tattered remnants of a radical sect, to a fully fledged terrorist group.

As it grew in power, subsuming whole towns by force, the group attracted more and more followers. Bands of armed robbers joined to exploit the chaos it left behind. Others joined to settle ancient scores against rival ethnic religious groups, mostly over land. Others were grabbed off the streets and forced into service.

Zakariyya, the young prisoner I met in 2011, had been coerced into joining Boko Haram. In the office of the Special Armed Robbery Squad in Maiduguri, my colleague, Abdullahi Kaura, and I listened as he finished his account.

As a boy, Zakariyya was brought up by his grandmother. His father was not around while he was growing up, and for a great part of his youth, neither was his mother. After his parents divorced, she had married a man who wanted nothing to do with him. After some time, Zakariyya said, his mother returned. She came back with some money, but when that ran out, the family did not have enough for him to continue to attend school. His mother had other, younger, children to care for. He left school with no qualifications and went out hawking. Selling shoes and phone accessories, he was able to take home between 2,000 or 3,000 naira a week (£10). Now 22, he said that he had two wives, and two children. He was struggling to feed his family when the men from Boko Haram offered to pay him to smuggle weapons.

“They promised me 200,000 naira,” he said, “but on the first trip they only paid me 70,000 and on the second trip they gave me only 40,000. I was never in favour of their ideology. They threatened me and said that now I knew what they were and who they were, I either did what they wanted or they would kill me. You cannot know their secret and just go. Once you know, you have to be part of them or they would just get rid of you. I was afraid for my life.”

They said now I knew what they were and who they were, either I did what they wanted or they would kill me Mohammed Zakariyya

When he was caught by the police, he told the officers what they wanted to know. “And, now the security forces have arrested me, I have pledged to assist them. Even as it is now, I’m in trouble. If they get me, I’m a dead man.”

Zakariyya’s voice was very faint. He looked very small.

Boko Haram’s violent network across Borno, Adamawa and Yobe went largely unchecked by the military. The group became bolder and began attacking towns in large fighting groups, travelling in convoys of stolen Toyota Hiluxes. Its tactic was to arrive in a town and announce itself at the mosque. After members of the group rounded up everyone they could, they would announce that the young men could either join them, or die. In February 2014, 59 young boys were lined up outside their school dormitory and murdered, their bodies thrown on a fire.

In March 2014 Boko Haram attacked the Giwa barracks in Maiduguri. In a video, men can be seen advancing on the military base, in the suburbs of a state capital under emergency rule. The fighters, many of whom are little more than boys, made almost no attempt to seek cover during their advance. When they broke in, they freed 800 people from the cells. Among the prisoners were people who were not members of Boko Haram before they had been picked up by the military. These people now faced a choice: they could not stay in prison, as they would surely die there. If they left and struck out on their own they risked being recaptured. Or they could leave with the group who had just liberated them.

The fate that met those who did not go with Boko Haram was discovered by Amnesty International: 645 people who refused join the militants were rounded up and executed, then dumped in a mass grave. For many, like Zakariyya, it must have seemed that their destiny was to join Boko Haram or die.

After our encounter with Zakariyya, my colleague and I stood outside the police station. We were both badly shaken. “They’re going to kill that boy aren’t they?” I asked.

Kaura nodded.

This article is adapted from Andrew Walker’s book Eat the Heart of the Infidel: The Harrowing of Nigeria and the Rise of Boko Haram (Hurst, 2016)

• Follow the Long Read on Twitter at @gdnlongread, or sign up to the long read weekly email here.