LONDON - Months after he was released from Guantanamo Bay, Abdul Rahman was back in the company of terrorist leaders along the Pakistan-Afghanistan border. But he was a double agent, providing Taliban and al-Qaida secrets to Pakistani intelligence, which then shared the tips with Western counterparts.

The ruse cost him his life, according to a former Pakistani military intelligence official, Mahmood Shah. The Taliban began to suspect him, and after multiple interrogations executed him.

The case of Rahman, which Shah recounted to The Associated Press, falls in line with a key aspect of the fight against terror - Western intelligence agencies, with help from Islamic allies, are placing moles and informants inside al-Qaida and the Taliban.

The program seems to be bearing fruit, even as many infiltrators like Rahman are discovered and killed.

It was a tip from an al-Qaida militant-turned-informant that led international authorities to find explosives hidden in printer cartridges from Yemen to the United States a week ago, Yemeni security officials say. Officials say the explosives could have caused a blast as deadly as the 1988 Lockerbie bombing in Scotland that killed 270 people.

Intelligence agencies such as MI6 and the CIA have hired more agents from diverse backgrounds since the terror attacks on Sept. 11, 2001, and others that followed. Many say the tactics have worked: Several plots, also including the 2006 trans-Atlantic airline plot, were thwarted because intelligence agents were able to use tips to track the terrorists.

In recent years, U.S., European and Pakistani intelligence officials have said al-Qaida has been weakened by CIA drone strikes along the Afghanistan-Pakistan border and by governments planting agents within terror cells. Top leaders have been taken out of the picture or trust has been eroded enough that militants have begun to turn on one another.

In an unprecedented public speech last week, MI6 chief John Sawers revealed for the first time that the British spy agency had managed to "get inside" terror organizations. He would not elaborate.

"Layers of al-Qaida's security have been slowly worn down, and it's much easier today to infiltrate these groups," says Noman Benotman, a former jihadist with links to al-Qaida in Afghanistan, Pakistan and Sudan, and now a security and terrorism analyst in London.

Saudi Arabia has had some of the most success with spies in the Arabian Peninsula, some of whom have been former Guantanamo detainees, Benotman says. Jail time at Guantanamo is a new asset on the résumés of many double agents, security officials say - an ultimate sign of credibility that often makes them revered and trusted among senior operatives.

The Saudis have a terror rehab program that has hosted about 120 of the nearly 800 men who have passed through Guantanamo since it opened nine years ago. Of them, about two dozen have taken up arms again, while a handful are thought to be working as spies for the Saudis.

Since al-Qaida stepped up efforts in the Arabian Peninsula between 2003 and 2006, Saudi Arabia has tried to aggressively infiltrate groups.

Some former militants have agreed to work with the Saudis because of lucrative incentives and the kingdom's ties to Wahhabism, an extremely strict and conservative form of Islam born in the Arabian Peninsula. For former Guantanamo detainees, the Saudis - unlike the Americans or Pakistanis - are considered less complicit in the capture and arrest of many prisoners.

"Saudi Arabia is one of the only countries to have made local intelligence contacts in Yemen, spending about $300 million a year to support this security network," said Maajid Nawaz, an Islamist formerly imprisoned in Egypt and who is co-founder of the Quilliam Foundation, a Muslim counter-extremism think tank in Britain. "They've also been able to successfully infiltrate tribes in Marib in Yemen. The financial incentive to some of these tribes has been strong."

Saudi officials declined to comment on intelligence operations.

Omar Ashour, head of the Middle East program at the University of Exeter in England who has studied the rehabilitation program in Saudi Arabia, said many of the men who go through the Saudi program have maintained strong militant links.

"These are very deep and strong relationships," Ashore said. "It may seem like some of the men would be considered traitors, but in actuality they gain back any trust they lost very quickly."

Once former militants complete the Saudi program, communications are monitored, Ashour said. Saudi officials even show up at family events such as weddings to monitor social contacts, he said.

Although Saudi Arabia has had some success using former prisoners, the results have been less successful in places such as Pakistan, where Rahman was executed for being a double agent. Afghanistan has had slightly better results using informants.

Analysts say other countries have also changed tactics or looked to former militant prisoners as informants.

Benotman said Algerians had destabilized terror groups by capturing top leaders and telling cell members they had been killed - all while keeping them as intelligence assets. One leader was thought to have been killed after his capture only to eventually reappear as a double-agent, said Benotman, who spent time in North Africa.

Indonesia, too, has stepped up intelligence efforts since the 2002 Bali bombings. More than 600 Islamic militants have been netted, around 20 of whom are actively working with police.