The United States is quietly being drawn into an escalating conflict in Yemen. Following the discovery earlier this month of a new bomb plot aimed at American airliners, the US government has been aiming drones at alleged members of al-Qaeda in the Arabian Peninsula (AQAP) at an unprecedented rate. Last week, US and Yemeni officials revealed that US special operations forces are on the ground in Yemen and that more may be on the way. Meanwhile AQAP, the Yemen-based organization now regarded by some officials as one of the principal terrorist threats to the United States, has stepped up attacks around the country, including a suicide bombing in Sanaa, the Yemeni capital, on Monday, that killed at least sixty people.

The new conflict may be as much about Saudi Arabia, the longtime US ally and Yemen’s northern neighbor, as it is about Yemen. To its continuing embarrassment, Saudi Arabia has long been known as the country that produced Osama bin Laden and fifteen of the nineteen September 11 hijackers. In recent years, the Saudi government has done much to reverse that image, in part by dramatically beefing up its own counterterrorism credentials and by becoming one of Washington’s key backers in the war against al-Qaeda. And yet, as I learned during a visit to Riyadh and other Saudi cities this month, it has struggled to contain another reality: that many members of AQAP are Saudi nationals who have relocated to Yemen, where they have been able to operate in relative freedom.

Take the recent bomb plot. There has been much comment in the Western press about the crucial part played by Saudi Arabia in its discovery. As multiple accounts now indicate, the sophisticated bomb was safely removed from Yemen by an apparent Saudi infiltrator of AQAP and turned over to the CIA. (The infiltrator, who may have had a Western passport, appears to have been run by Saudi intelligence officials in close collaboration with their British and American counterparts.) But the bomb itself was also designed by a Saudi national—a man who has devised daring large-scale attacks aimed not only at the US but also at the Saudi government itself.

How did Yemen become the base of Saudi terrorism?

The story begins in the decade after 9/11, when two key figures, both Saudis, emerge in the confrontation between counterterrorism agencies and al-Qaeda-inspired groups. One is Prince Mohammed bin Nayef, the head of Saudi Arabia’s counterterrorism force and son of the country’s Interior Minister and heir apparent, Crown Prince Nayef. The other is Ibrahim Hassan al-Asiri, a young former chemistry student, who became radicalized and went to Yemen, where he has emerged as the talented and dangerous chief bomb maker of AQAP.

Prince Mohammed is often credited with turning around his country’s disastrous reputation for terrorism. Following a wave of horrific attacks on Saudi Arabian soil in 2003 and 2004, he has led a crackdown on terrorist financing—Saudi Arabia-based charities are well known to have financed extremism in Afghanistan and elsewhere since the 1980s—and helped Saudi Arabia become a key player in Western counterterrorism efforts. Along the way, Saudi security forces largely destroyed al-Qaeda’s network inside Saudi Arabia itself and Prince Mohammed founded a much-publicized rehabilitation center for former and aspiring jihadists.

But while the rehabilitation center has successfully graduated hundreds of former low-level militants, it has not been able to prevent some of the most hard-core Saudi jihadists from relocating to Yemen, where in early 2009, they merged with Yemeni counterparts to found AQAP. Officials from the Saudi Interior Ministry told me that an estimated one hundred Saudi radicals may now belong to AQAP, and nearly all of them are believed to be in Yemen. (In 2009, the Saudi government published a list of eighty-five most wanted terrorist suspects, of which I was told fifty-six are still at large; and a more recent list includes an additional forty-seven men, though a few of these are Yemeni nationals.)

The most notable of these Saudi exiles is Ibrahim Hassan al-Asiri, who has proven as dangerous a threat to Saudi Arabia as to the United States. Al-Asiri came to the attention of US terrorism experts in late 2009 as the presumed designer of the failed Christmas Day bomb (the plastics explosive device carried by the so-called “underwear bomber” on a Detroit-bound airliner). But by that point he was already notorious in Riyadh as the mastermind of one of the most daring suicide bomb attacks in Saudi history. In August 2009, al-Asiri had provided a similar kind of bomb to his brother, who nearly succeeded in assassinating Prince Mohammed at his office in Jeddah. Still more disturbing, the assassination attempt appears to have been carefully designed to turn Saudi Arabia’s particular approach to counterterrorism against itself.

In setting up the rehabilitation center, Prince Mohamed and other Saudi officials placed great emphasis on getting jihadists to “repent” and recognize their ideological errors rather than languish for years in prison; in return, the government grants them an opportunity to reenter society as reformed citizens with extensive government support. (Among other things, the center, which I toured with a group of American journalists, puts considerable effort into finding wives and jobs for the men who complete its courses—steps considered essential to reintegration in the country’s family-bound society.)

But the Saudi approach did not go unnoticed by AQAP. In the days leading up to the 2009 assassination attempt, al-Asiri’s brother made contact with Prince Mohammed, saying he was ready to “repent” and wanted to meet in person to turn himself in. As a sign of honor, the prince granted his request. The bomber detonated himself and the prince miraculously escaped with minor injuries. Nevertheless, the attack was a powerful reminder that Saudi terrorists were still at large in the region and the usually reticent Saudi government felt it necessary to publicly defend its rehabilitation strategy.

Why is AQAP intent on attacking Saudi Arabia, a country that adheres to one of the most conservative forms of Islam in the world? Saudi Arabia holds special significance as the seat of Islam’s holiest sites; and the monarchy’s close ties to Western governments—before and since 9/11—have rankled fundamentalists. According to Saudi officials, AQAP is upset with Riyadh’s renewed alliance with the United States, which Saudi officials believe the 9/11 attacks were designed to destroy. Indeed, the wave of terrorism that swept Saudi Arabia in 2003 and 2004 was largely aimed at Western targets within the Kingdom, though hundreds of Muslims were killed as well.

Paradoxically, AQAP’s recent offensive seems to have led instead to greater collaboration between Saudi and US officials—and, if reports are to believed, reliance on the Saudi rehabilitation approach. Saudi counterterrorism agents helped investigate the Christmas Day bomb plot, and in 2010 they discovered the AQAP plot to put bombs designed by al-Asiri on cargo planes—intelligence which they shared with the US and other “friendly countries” (Saudi officials apparently even gave US officials the tracking numbers of the bomb packages). Moreover, the Saudi rehabilitation center may have been a key asset in uncovering the 2010 plot: According to Yemeni officials, the tip about the cargo bombs came from an Saudi national, Jabir al-Fayfi, who had been released from Guantanamo and gone through the rehabilitation center in Riyadh before joining AQAP in Yemen, apparently as a plant.

If this report is accurate, it may indicate the methods used by the Saudis to disrupt the most recent bomb plot as well. According to press accounts, the agent who infiltrated the bombmaker al-Asiri’s cell in recent months also supplied the US with information about Fahd al-Quso, a Yemeni terrorist wanted in the 2000 bombing of the USS Cole who was killed in a drone attack on May 6. (Saudi officials have until now declined to comment on their involvement in the recent events.)

One conclusion, then, may be that the Saudi government has not only been able to use the country’s vulnerability to extremist movements to gain new insight into al-Qaeda and the recruiting process; it can also draw on rehabilitated former jihadists to further its intelligence efforts. Moreover, Saudi Arabia has long cultivated ties with various Yemeni tribal leaders, and with deep historic connections between southwest Saudi Arabia and Yemen, Saudi agents are well placed to penetrate the deep tribal networks in which AQAP is said to be embedded.

But al-Asiri and other Saudi members of AQAP have yet to be caught, and the 2009 assassination attempt suggests the Saudi approach can sometimes backfire. (Saudi officials also acknowledge that a small number of those who have been rehabilitated have returned to jihadism, including several former Guantanamo detainees who later joined AQAP.) In any case, the Saudi border with Yemen is 1,100 miles long, much of it in the remote desert of the Empty Quarter, which is extremely difficult to secure; and Interior Ministry officials say that those same tribal networks help al-Qaeda members smuggle arms into Saudi Arabia and undertake cross border operations.

What seems clear is that Saudi Arabia has become a key backer—and at times coordinator—of the accelerating US drone war and special operations offensive in Yemen, partly for its own security interests. Interior Ministry officials in Riyadh speak enthusiastically about the US drone program, and on May 12, drone strikes allegedly killed some eleven AQAP suspects, two of them Saudi nationals. (It is worth noting, following the controversial killing of US citizen Anwar al-Awlaki, that Saudi Arabia does not appear to have many qualms about killing its own citizens in Yemen.)

Perhaps most important for the Saudi government, a successful counterterrorism policy carries enormous political value amid the upheavals of the Arab Spring. Even more than democratization or regime change in the region, the Saudi rulers seem to fear instability and unpredictability: though they have reluctantly supported the transition of power in Yemen, they are particularly nervous about the kind of extremism that has emerged in neighboring countries like Iraq, Yemen, and now Syria, when uprisings turn into violent conflict or authority breaks down entirely—places where Saudi jihadists have often found new causes. “Syria will be tempting to al-Qaeda,” Abdulrahman Alhadaq, a Saudi counter terrorism official, said in a briefing in Riyadh. “We need to avoid another Iraq.”

But Saudi counterterrorism efforts are also an important element in achieving consensus and legitimacy for the Saudi regime itself. Many young Saudis are growing increasingly impatient with their government’s oppressive status quo, and not a little of their ire is directed against the Interior Ministry, which has been blamed for arbitrary arrests of activists and human rights lawyers. Yet many I spoke to also seem to fear the chaos and violence that has engulfed so many of the country’s neighbors. In the early 2000s, when the Saudi government sponsored national dialogues to bring together activists, reformers, conservatives, and Islamists from across the ideological spectrum to suggest avenues of change, the country’s counterterrorism approach was one issue on which there was near universal agreement. (Participants in one of these dialogues explicitly endorsed a strategy of repentence and reconciliation for extremists.)

Turning Saudi Arabia into the US’s indispensable ally in Yemen—while making Yemen the central conflict in the US-led war against terrorism—has considerable strategic value for Crown Prince Nayef, who was named the heir apparent to King Abdullah last fall. As US-Saudi collaboration on security and counterterrorism has increased, the regime has largely avoided US pressure on human rights and domestic reforms. And while it keeps the terror threat at bay, at least within its own borders, the Interior Ministry can hold up Yemen as the example of what might happen at home if its broad powers were curbed. Whether that argument will continue to assuage the country’s youth remains an open question.

Hugh Eakin traveled to Saudi Arabia on an IRP Gatekeeper Editors trip organized by the International Reporting Project in Washington, D.C.