In both a new book and an interview with NBC News, a British spy inside al Qaeda says his cover was blown by a leak to reporters that likely emanated from Vice President Dick Cheney's office. The leaked information ended his seven-and-a-half-year stint as a mole inside the terror group.

The spy, who now goes by the name Aimen Dean, writes of his career and its dramatic end in "Nine Lives: My Time as the West's Top Spy Inside al Qaeda," co-authored by Tim Lister and Paul Cruikshank and released in the U.S. Tuesday.

Dean, a Saudi national who went to Bosnia to fight for al Qaeda at age 16, was an expert in weapons of mass destruction as well as the terror group's complicated hierarchy. He writes in "Nine Lives" of meeting both Osama Bin Laden and Khalid Sheikh Mohammed, the mastermind of the 9/11 attacks, on multiple occasions. He also met famed American jihadi Adam Gadahn, which would later come back to haunt him.

After becoming disillusioned with al Qaeda, Dean flipped and became a mole for the British in 1999. American intelligence officials say that by staying inside al Qaeda and working undercover he thwarted attacks and saved lives.

But his career as a double agent ended in June 2006 when details of some of his biggest successes showed up, without warning, in a Time Magazine excerpt of the book "The One Percent Doctrine," by journalist Ron Suskind.

Dean, who traveled between the Middle East and Europe, was in Paris on vacation when one of his al Qaeda comrades sent him a text with a link to the Suskind story, warning, "Brother, go into hiding. There is a spy among us." The text didn't accuse Dean of being the spy but he believed it was only a matter of time before he was outed.

"I was angry," Dean told NBC News. "I thought, 'The information was supposed to be under wraps! Why is it splashed all over Time Magazine?' Both MI6 and MI5 were shocked. Neither knew about it."

His British handlers pulled him from the field immediately. They ordered him to take the Eurostar train to London as soon as possible. Within five hours, he was being greeted on the platform at Waterloo Station by one of his MI6 handlers.

Dean noted that the book's portrait of the mole, a trusted member of al Qaeda who had provided details of a planned 2003 attack on New York's subway, identified the head of al Qaeda's WMD program and stolen the group's design for a terror weapon and given it to Western intelligence, was so detailed it could only fit a few people. The spy was even identified as "Ali" — his birth name and the one he used within al Qaeda. "Every paragraph provided another detail about Ali, until the full picture emerged looking distinctly like me," he writes in "Nine Lives."

After a flurry of cables between British intelligence and the CIA, Dean said his handlers told him who they believed was responsible for the leak — someone in Cheney's office.

"Nine Lives: My Time as the West's Top Spy Inside al-Qaeda" by by Aimen Dean, Paul Cruickshank, and Tim Lister. Oneworld Publications

"The whole saga of discussions took about two weeks for them to ascertain who was responsible," Dean told NBC News. "There were lots of cables that went from MI6 into the CIA and back. MI6 wanted to know why information that was shared in good faith had been leaked when there was no necessity to identify who the spy was.

"The CIA defended itself by saying [the leak] had most likely come from someone in the political sphere who had access to the information," said Dean. "The book was centered around Vice President Cheney and burnished the image of Cheney."

A former U.S. intelligence official tells NBC News that at the time "there was a lot of angst inside the agency about the Suskind book for a variety of reasons," without providing details on classified materials.

When contacted by NBC News, Ron Suskind said, "Like all major disclosures in my books, the array in ‘One Percent Doctrine’ were vetted just prior to publication with CIA officials to ensure sources and methods would not be compromised."

'I was a powder keg yearning for a spark'

Dean, a Saudi national, had been critical to British — and by extension U.S. — intelligence since the late '90s, when he soured on al Qaeda over what he says were moral concerns.

He had gone to Bosnia as an idealistic teenage jihadi to fight the Serbs, following in the footsteps of a teacher who was a role model. Says Dean, now in his 40s, "I was imbued with an ideology, but I was also a powder keg yearning for a spark. I did not want history passing me by."

The loss of more than 200 civilian lives in the East Africa embassy bombings of August 1998 had sickened him, he says, and al Qaeda leaders' justification of the attacks on Koranic grounds felt thin at best.

"Amid these doubts," he writes, "the wrangling inside me, I did know one thing: The moral clarity I had felt setting off for Bosnia was gone forever."

Dean, who had been in Afghanistan, flew to Qatar to get away from al Qaeda. Qatari intelligence officials pulled him aside and said they had identified him as someone who had used the cellphone of a top al Qaeda official.

Dean told the Qataris that he no longer believed in al Qaeda and was ready to act as a mole inside the organization. The Qataris told him he should work for Western intelligence instead, and offered him the chance to work for the U.S., the British or the French. They gave him a half hour to decide.

Dean, who didn't speak French and was wary of the Americans, chose the British.

"I was suddenly and perhaps irrationaly excited about my new lease on life. My appetite for adventure and movement had briefly stifled any apprehension I might have had about such a sudden and drastic change of course."

The Qataris flew him to London in December 1998, where he met his new British employers. Initially, he planned on working for "Her Majesty's Secret Service" for a few months, but British intelligence had different plans for him, particularly with his extensive knowledge of how al Qaeda worked.

They sent him back to Afghanistan, where he trained in bomb making at one of al Qaeda's most notorious camps, all the while sending information back to MI6.

His biggest coup was providing the Brits with the design of a chemical warfare dispersal device manufactured from parts that could be found in a tool shed and was capable of spreading deadly cyanogen chloride or other agents. He had carried the design out of the Middle East on floppy disks. His information was so detailed that the CIA was able to construct a copy and bring it to Cheney's office.

Dean's belief he would eventually be found out was confirmed two years after his escape to London, when MI6 learned that there was a fatwah on him. Any Muslim who encountered him was ordered to kill him. Adam Gadahn had identified him.

"Not for the first time I felt a stab of anger toward the leaker or leakers who had briefed Ron Suskind," Dean writes in his book. "With two terms nearly completed, many senior officials in the Bush Administration were looking forward to lucrative jobs in the private sector or six-figure book deals. I, on the other hand, was on al Qaeda's list of things to do, thanks to some loose lips in Washington."

Asked Friday if he remains in fear for his life, Dean said that for the most part, he is not. "Basically, those who have threatened me are dead themselves," Dean said with a smile. Bin Laden was killed in a U.S. raid in 2011, while Gadahn died in a U.S. airstrike in 2015.

A representative for Cheney did not respond to a request for comment.