Aimen Dean was an early member of al-Qaeda, who changed tack in 1998 and became a spy for Britain's security and intelligence services, MI5 and MI6. Interviewed by Peter Marshall, he describes his years working in Afghanistan and London as one of the West's most valuable assets in the fight against militant Islam.

Bosnia

Dean was brought up in Saudi Arabia, where opposition to the Soviet occupation of Afghanistan in the 1980s made military jihad a noble concept. He was a teenager when Yugoslavia splintered, and Bosnian Muslims found themselves in mortal danger from Serb nationalists. He and a friend, Khalid al-Hajj - later to become the leader of al-Qaeda in Saudi Arabia - set off to become mujahideen.

I would say it was the most eye-opening experience I ever had. I was a bookish nerd from Saudi Arabia just weeks ago and then suddenly I find myself prancing up on the mountains of Bosnia holding an AK-47 feeling a sense of immense empowerment - and the feeling that I was participating in writing history rather than just watching history on the side.

And also at the same time, being in the military training camps, receiving knowledge that I never thought in a thousand years I would be receiving about warfare and war tactics and military manoeuvres, and to be receiving it alongside people from many different nationalities, with the one common factor among them that they were all Muslims. And they were all there in order to participate in the jihad in defence of the Bosnian population, was in itself also an overwhelming experience.

Q:You weren't afraid?

A:Between you and me, I think at the beginning I was afraid of the unknown rather than afraid of the fact that I'm going into, embarking on a journey that might end up with all of us being killed actually.

Q:You didn't fear death?

A:I would be lying if I say no I didn't fear death but I started to come to peace with the idea that yes, I am entering Bosnia. Most likely I will never come out of it.

Q:Did you want martyrdom, did you want to die?

A:Yes.

Jihad school

By the end of the Bosnian conflict I started to notice something else within my comrades. Those who survived started to adopt a rather more anti-Western, anti-globalisation feeling that the global community were conspiring against the Muslims in Bosnia because they were turning the tide of the war in their favour - so they wanted to end the war there and then before they score any more victories.

Find out more This is an edited version of Peter Marshall's interview with Aimen Dean, which was broadcast on The Spy Who Came in from al-Qaeda, on BBC Radio 4 at 09:00 GMT on 3 March. You can catch up via the BBC iPlayer Radio. Catch up with Peter Marshall's interview with Aimen Dean on Islamic State - an edition of The Report broadcast on BBC Radio 4 in January 2015.

At least that's the perception. And with that perception, I think they started to feel that the West is fighting Islam as a religion… and that led to further radicalisation that made it easy for them to make the transformation from being mujahideen into being jihad operatives.

Bosnia was a school in which many talented leaders of al-Qaeda were born. Khalid Sheikh Mohamed [accused of being the architect of the 9/11 attacks] was one of those people who were in Bosnia.

The impression I had at that time, was that he was there in Bosnia in order to spot talent, let's put it this way, in order to you know scout for talents who will be useful for the later struggle.

I remember that one of the things he said, and it was in a wedding where we were seated next to each other basically, and one of the things he said, he said, "Well, the Bosnian war seems to be ending here, that you know the end is in sight but what will happen after the war? The question is are we going to roam the globe from one hopeless battle to another trying to save a Muslim population until someone else, and then someone else come and reap the reward?"

In other words, there will be a government that is secular and doesn't rule by the rules of Sharia. He says that this cycle need to end and that we have to think about another front where we can serve Islam and basically resurrect the spirit of jihad within the Muslim world. I think that little speech was the first indication that things are moving from jihad being an instrument to defend Muslim populations on the frontiers to an instrument to bring down regimes and to fight a terror war… against the US interests in the region.

Q:To become terrorists rather than soldiers?

A:Absolutely.

Media playback is unsupported on your device Media caption 'Aimen Dean' said he was going public to confront jihadists

Joining al-Qaeda

I was invited to Kandahar to give the allegiance basically and as with everyone who give allegiance Osama bin Laden will give you know a one-to-one meeting basically with those who are joining and then he welcomed me into the fold. He basically said that there will be many, many years of difficulties and hardship, and that the cause of jihad is not going to start with him or end with him.

Q:You swore an oath?

A:Yes.

Q:What was the oath?

A:"I give you an allegiance to fight alongside you in good times and in bad times and to fight the jihad against the enemies of god and to obey my commanders."

Q:What were you doing when you were swearing the oath? Do you stand, do you kneel?

A:You sit next to him on the floor basically and you know you have your hand on a copy of the Koran and you say it. Almost knees touching each other basically.

Q:And this is a moving moment presumably?

A:Yes, although like you know I have to say looking back at it basically, I felt you know the same dread of the unknown that I felt before I went to Bosnia.

Q:You knew it was a big leap you were taking?

A:Yes.

Image copyright Other Image caption Aimen Dean as a child

Afghanistan

At home in Saudi Arabia Aimen Dean had been a Muslim theological prodigy. In Afghanistan it was his responsibility to train al-Qaeda recruits - many from Yemen - in the basics of Islamic theology and history and the essentials of religious practice. This opened his eyes to the jihadists' different motivations.

There is no single process of radicalisation. Some people, it took them years to be convinced of coming to the jihad and some people it took them minutes. Some people were studying in religious seminaries - they're a minority by the way - and then decided to come and some people basically just came straight out of a night club you know while he was consuming alcohol basically to come and seek redemption there in the jihadist world.

So you know you see immediately that you know there isn't one single classical journey there, that there are so many journeys.

Q:But they all want martyrdom?

A:They all want martyrdom and redemption and to various degrees. Some people will come to you and say you know I'm really tired, I want to be martyred as soon as possible. And some people will come to you and say I want to be martyred but not before I give the enemies of god hell on this earth. I want to live for as long as possible to give them as much hell as possible and then taken out by them.

Q:So some, some are basically suicidal to begin with, and others just have blood lust?

A:Yes.

Doubts

Dean was at a training camp in Afghanistan when the bombings of the US embassies in Nairobi and Dar es Salaam took place in 1998. He was concerned to learn that as well as the 12 American casualties, 240 or more local people died, and 5,000 were wounded.

I think that is when the horror of it started to sink in. And this is when I realised that if this is the opening salvo of this war, where is the next target? Argentina, South Africa, Mozambique? Are we going to fight Americans in Africa in order to expel them from the Middle East, from the Arabian peninsula? It just didn't make sense.

And as a theologian, that's when I started to have doubts about the legality of the whole thing. So I started to ask questions. I went, I remember, to Abdullah al Mohaja, who was the de facto mufti of al- Qaeda… I said, "It's not that I have doubts or anything but can you please enlighten me about the religious justifications for attacking an embassy belonging to the enemy, yes, but at the same time the fact that it's surrounded by potentially huge collateral damage?"

And he said to me, "Well look, there is a fatwa issued in the 13th Century AD throughout the Muslim world, which legitimises attacking an enemy even if it means there are civilian deaths because the enemy is using them as a human shield." And he said, "This fatwa is comprehensive, it gives us justification and there is no doubt about the legality of what we have done."

Image copyright AFP Image caption Collateral damage: Rescuing casualties of the Nairobi embassy bombing

So I decided to go and look for myself, and this is when I received a big shock. The fatwas were issued in response to questions sent by Muslim cities in Central Asia, Tashkent, Samarkand, Bukhara, asking this particular question: "Look, the Mongols are invading. Every time they sack a city, they take a segment of the population from that city, a thousand or two or three, and make them push the siege towers towards the walls of the next city. So do we shoot at our fellow Muslims, who are against their wills pushing the siege towers into the walls of our city, or not?"

And then the fatwa came: "Yes, this is a case where the Mongols are using civilian Muslims as human shields in order to achieve a military aim and if you don't shoot at them, you will end up being killed yourself if the attacks succeed."

Now when I learned of this, I was thinking: "OK, how do I reconcile this fatwa which applies to a life-and-death situation, regarding a vicious enemy using people as human shields to sack another place and to kill every man, woman and child in that city, with what happened really in Nairobi and Tanzania?" There is no resemblance here.

Q:And this fatwa based on siege towers from 800 years ago, that's what's used to justify all acts of jihadi terrorism?

A:That would result in civilian casualties, yes.

Q:So it's important?

A:It is important but you know I'm not going to say it has shaky foundations. It has no foundations at all. It's basically castle of sand in the air.

Q:It's nonsense?

A:Absolutely, and two months down the line I decided that it's no longer for me and that I wanted to leave.

Becoming a spy

Still barely out of his teens, and deeply troubled, Dean says he went to the Gulf for medical treatment, having privately decided not to return. Instead, he found himself in the hands of MI6. In 11 days, he says, he was turned. After four years and two months as a jihadi, he landed in London on 16 December 1998, and the debriefing began.

I think seven months of debriefings, that was more or less helping them put together a better picture of these organisations and the groups and who are the influential people within them.

Q:Because you knew Osama Bin Laden, Khalid Sheikh Mohamed, Abu Zubeida. You knew everybody.

A:Yes… Seven months into the debriefings, that's when the suggestion [came]: "What about you going back to Afghanistan and doing some more work for us?" And my answer was unequivocally, "Yes." I didn't have any qualm with that at all.

Q:What did you do?

A:Passing back information, that's what my primary objective was, to collect as much information as possible - and that wasn't an easy task because you have to rely entirely on your memory. You can't write anything. Everything has to be stored in the mind, nowhere else… Whatever moral misgivings I had, I have my ex-comrades to thank for driving those moral misgivings away because the more I see what they were planning - for example, I was there basically when al-Qaeda was constructing their first workable chemical device and talking about this with such glee and such deep psychopathic satisfaction… - that is when you say to yourself, "Why do I have any moral misgivings about spying on you guys?" Whatever they are doing is justifying whatever you are doing.

Q:You had to play along with them obviously?

A:Of course. I was still preaching, I was still stating how committed I am to the cause.

Q:That must be tricky, though, because in some ways because you're there preaching, you're again giving theological justification for some of the bad things that you know that they're up to.

A:Yes, but at the end of the day if you want to catch rats, you have to go into the sewage system basically and get dirty yourself.

Q:So you were in Afghanistan and you were coming back and forth to the UK as well.

A:Yes.

Q:But al- Qaeda thought they were sending you back to the UK presumably?

A:Yes. I think that's the beauty of it.

Q:So they think you're working for them?

A:Yes.

Q:When you're actually working for the West?

A:Absolutely.

Image copyright Other Image caption Aimen Dean in Mecca

Spying in London

While in the UK Dean would be watching and gathering information on people like Babar Ahmed, a British man who admitted providing material support to terrorists, and Abu Hamza, convicted in the US earlier this year of supporting terrorism, and Abu Qatada, who was cleared of terrorism charges by a court in Jordan last autumn after a long legal battle to extradite him from the UK. Dean kept an eye on them and others while preaching in mosques and Islamic societies.

Q:The difficulty is though that if you're there under cover, welcomed there as an al-Qaeda man, you have to keep up this pretence by talking to people at the mosque, you have to encourage them to join the jihad?

A:Yes… although there are limits. I was aware of my boundaries basically about how much you can incite. You use guarded words about general rather than specific incitement. But then the most difficult part actually was after 7/7, 2005. That's when the laws and regulations regarding incitement like you know were really tightened.

Q:So you couldn't say what, and you could say what?

A:You can't specifically urge someone to go. You can't specifically call for an attack. You can't glorify violence committed against civilians. You know you have to be careful there. You can sit down there basically and blast the West for what they do. You can sit down there and talk about martyrdom in general without you know touching directly on what's happening right now. So you have to be clever about how you phrase your words.

Q:Do you ever feel guilty about having encouraged somebody to go to jihad?

A:Yes.

Q:Are there many occasions that this might have happened?

A:There were some occasions where that happened.

Q:What's the nature of the guilt, because of what they might have been involved in or because of how they ended up?

A:I'm glad that no one was killed. However, one particular person ended up in prison for a long time.

Q:And you were instrumental in getting him out there?

A:I was a contributing factor but I wasn't the only one.

Saving lives

Dean says he foiled attacks involving suicide bombings and the use of poisons against civilians. He was also able to hand plans to British intelligence of a device that was intended to be used for a chemical attack on the New York subway. In the event, Osama Bin Laden's deputy, Ayman al-Zawahiri, called off the attack.

They would have used chemical weapons if it wasn't for al-Zawahiri saying, "No, don't use it."

Because it was a cell that was seeking permission from al-Zawahiri saying, "We are in possession of this weapon, we know how to use it now, we know how to deliver it and we have a target for you. It's the New York subway because we believe that the subway system with all the ventilation mechanism there will be a perfect vehicle for delivering the gas and dispersing it across a wide network."

And so that's where Zawahiri said, "No, don't do it because the retaliation could get out of control."

Q:He didn't stop it because he thought it was the wrong thing to do, to put gas on the subway?

A:He stopped it because he was afraid of the ramifications.

Q:So you got these important plans. Can you tell me where you got those plans from?

A:Well, I wouldn't say even if I was allowed to!

Q:The fact you got those plans though suggests you had a high degree of clearance in al-Qaeda, trust.

A:I think I was privy to these plans because I have a certain talent, and I [pretended I] wanted to use that talent for enabling these attacks. That's why.

Q:That's what al-Qaeda thought?

A:Yeah.

Q:What was your certain talent?

A:I wouldn't say!

Valued first by al-Qaeda and then British security and intelligence, Aimen Dean's life under cover came to an abrupt end when the cover was blown. An American writer disclosed his identity with details that could only be sourced to Dean. That was eight years ago.

This is an edited version of Peter Marshall's interview with Aimen Dean, which was broadcast on The Spy Who Came in from al-Qaeda, on BBC Radio 4 at 09:00 GMT on 3 March. You can catch up via the BBC iPlayer Radio.

You can also catch up with Peter Marshall's interview with Aimen Dean on Islamic State - an edition of The Report broadcast on BBC Radio 4 in January 2015.

Subscribe to the BBC News Magazine's email newsletter to get articles sent to your inbox.