This story is the result of a two-year CNN investigative report. "The Jihadi Code," a documentary on the breakthrough, airs on November 28 at 1730 GMT and November 29 at 1200 and 1930 GMT.
Tripoli, Libya (CNN) -- The long and intricate peace negotiations between the Libyan government and a radical Islamist group were nearly derailed by the sudden death in a Tripoli prison of a prominent Libyan Jihadist, Libyan sources revealed to CNN.
As the negotiations entered a critical phase early this year, Ibn Sheikh al Libi was found dead in his cell at the top security Abu Salim prison in Tripoli.
In May, Libyan newspapers reported he had hanged himself in his prison cell with his own bedsheets. But in Jihadist circles worldwide, and among some members of the Libyan Islamic Fighting Group inside the prison, there were suspicions he had been murdered.
Just the previous month al Libi had been pictured with his daughter for cameras inside Abu Salim prison -- a photo exclusively obtained by CNN.
Although al Libi was not formally a member of the LIFG he had close and long-standing personal connections to many of the group, according to Libyan sources.
He had run the Khalden training camp in the 1990s in Afghanistan, a facility used by al Qaeda and the LIFG. He was detained late in 2001 in Pakistan and handed over to the United States military. He was subsequently transferred to custody of a "third country" where he subsequently claimed he was tortured, according to a September 2006 Senate Select Committee on Intelligence report.
A declassified CIA cable disclosed that country was Egypt. Egypt has not commented on the affair. While in custody al Libi told the "foreign government service" that Saddam Hussein provided chemical and biological weapons training to Al Qaeda operatives, according to a Senate report. In 2004 Al Libi recanted the claim, claiming it had been made to stop the torture, according to the Senate report.
Despite the fact that U.S. intelligence officials raised red flags about the credibility of his testimony in early 2002 according to the Senate report, the testimony was later used by the Bush administration to make the case for the war in Iraq.
Al Libi was transferred to Abu Salim prison in 2006, according to Libyan sources.
His family was able to visit him for the first time in April 2009 because of an improvement in prison conditions forced through by Saif Gadhafi, the son of Libya's leader, in a bid to break the deadlock in peace talks between the Libyan government and the top LIFG leadership.
Although much progress had been made in the talks one key LIFG demand had not be met: an easing of restrictions inside prison so militant leaders could consult with some 200 rank and file members to get their backing to start work on the Corrective Studies text that would formally end the fighting.
Memories of a bloody riot inside the prison in 1996 meant that allowing LIFG members to mix was a redline the security services did not want to cross. "They were afraid our people that to bring the members with the leaders in then same place then you can have an uprising," Gadhafi told CNN.
Most branches of Libya's security services had been skeptical of the talks from the start, and had only taken part because they had been prodded to do so by Saif Gadhafi, according to a source briefed on the talks.
Read how progress was linked to Saif Gadhafi's battle with the old guard in Libya
But in early 2009 Gadhafi won a key ally in pushing the peace process forward -- Abdullah al Sanussi, a very powerful figure within Libya's security services, according to Libyan sources. In early April prison officials started to gradually reorganize the prison.
But al Libi's death -- just as the LIFG was about to start writing its text -- threatened the whole process.
Few within the LIFG bought that it was a suicide. Abdul Ghani al Amari, a mid-level member of the group living in London told CNN: "When I heard the news of his death and it was reported as suicide, I didn't think it was likely because he was a religious man and I don't believe he would do such a thing. As to how he died, God only knows, I have no idea."
Saif Gadhafi feared that al Libi's death could jeopardize the talks, according to Libyan sources. He pressed prison officials to meet the LIFG's demands for better prison conditions. "They can [now] stay with their wives, they can see their families. Sometimes they go to their homes and back to jail. They are not living in cells [but] in a reasonably good residence, good treatment, drink, food, visits, books, TV, radio, satellite, Al Jazeera, CNN," Gadhafi told CNN. The move paid off, reassuring the leaders of LIFG of Gadhafi's commitment to the peace process.
It took the LIFG just three months to complete its rank and file consultations and write Corrective Studies. Lotfi Kreir, a rank and file member imprisoned in Abu Salim, told CNN how he, along with other members, met with Abu Mundhir al Saadi, the LIFG's religious guide in the early summer of 2009 in the administrative office of the director of the prison.
Al Saadi told them the group had previously gone down a mistaken path, that it had been wrong to fight Jihad in Libya, and that the revisions were taking place out of belief and not coercion. "I trusted him, because he was being frank and honest and admitting fault," Kreir told CNN.
Read how the Libyan peace deal is hitting al Qaeda
The authors of the "Corrective Studies" made clear just how fundamental a shift they have made in their thinking: "It is not a secret to say that the very same people who wrote this book used to conduct a lot of research and write articles that were completely against the ideas expressed in this book. We are the same people. And that fact has been revealed to the whole world.
"We used to encourage armed struggle and now we stand here today saying that it is illegitimate. We hope to influence anybody who can be reached by our advice to try to avoid armed struggle."
On October 15 the Libyan government released 88 mid-ranking and junior members of the LIFG. Saif Gadhafi told CNN that he hoped that some of them will eventually take pro-active steps to counter al Qaeda's ideology in Libya, but that "the most important thing right now is to how to rehabilitate them ... how to engage them with us in the society and then we talk about this advanced step."
Shortly after the prisoners were released Saif Gadhafi instructed Libyan officials to take measures to integrate the prisoners into society. Under his scheme each prisoner will be compensated a lump sum of the equivalent wages they would have earned during their years in prison and offered similar jobs to the ones they held before they were arrested, according to Libyan sources.
Gadhafi told CNN that in time the Libyan government will "release the leaders and then we empty the prison. There will be no Libyan Fighting Group members in our jails."
But one Jihadist never made it out alive. Mystery continues to surround his death.