Nearly three years ago, a Saudi Arabian university student applied for a passport to travel to Syria or Iraq, where he hoped to join two cousins fighting for the extremist group now known as Islamic State.
The soft-spoken 29-year-old in a crisp white tunic said he had been incensed by the violence he saw directed at his fellow Sunni Muslims by those governments and U.S. forces. "I wanted to go fight for justice," he said.
Young Saudis like Badr, who asked that his last name not be used because of safety concerns, are part of a new extremist threat in the Saudi kingdom, whose leaders have sought to insulate the world's top oil producer from the wars raging around them.
Although Badr didn't get far — he was arrested when he went to collect the passport — nearly 2,300 Saudis are believed to have joined the ranks of Islamic State and other groups fighting in Syria and Iraq. Hundreds have now returned home, bringing with them fighting skills honed on foreign battlefields and a lethal agenda.
On Friday, Islamic State claimed to have carried out its second suicide bombing on Saudi soil in a week, part of a rash of attacks that have hit the normally battened-down kingdom since November.
The bombings, which together killed 25 people and injured more than 100, were aimed at the country's Shiite Muslim minority, viewed by Sunni extremists such as Islamic State as apostates. Security officials have also linked the group to an assault that killed a general in charge of security on the kingdom's northern border with Iraq, and a string of shootings aimed at police, Westerners and Shiites.
For years, wealthy Saudis have been accused of nurturing the fundamentalist brand of Islam that inspires many jihadists in the Middle East and beyond. Of the 19 hijackers involved in the Sept. 11, 2001, attacks against the United States, 15 were Saudi citizens. Weapons and cash from Saudi Arabia have flowed to armed groups fighting the government of President Bashar Assad in Syria, who is allied with the kingdom's chief regional rival, Shiite-led Iran.
Now Saudi Arabia itself is increasingly becoming a victim of Islamist violence, aimed not only at Shiite minorities, but also the royal family, seen by militants as corrupt, oppressive and beholden to allies in the United States and Europe.
Saudi officials say they don't support extremists like those of Islamic State and Al Qaeda-affiliated Al Nusra Front in Syria, which they have designated as terrorist groups, and have worked to halt the flow of support from their citizens.
"I don't see how we can finance or encourage terrorism when we are being targeted by such groups," said Maj. Gen. Mansour Turki, an Interior Ministry spokesman.
Saudi Arabia is the birthplace of Islam and home to its two holiest cities, making it a hugely symbolic target for a group that claims to have restored the caliphate, a form of Islamic rule that ended with the Ottoman Empire. Nearly 400 people have been arrested on suspicion of setting up networks and plotting attacks on behalf of Islamic State since last year, most of them Saudi nationals, Turki said.
The group's leader, Abu Bakr Baghdadi, made his intentions clear in a November audio recording in which he declared that the caliphate was expanding into the land of "Haramayn," or the two holy sanctuaries in Saudi Arabia, Mecca and Medina.
Baghdadi instructed his followers in the kingdom to prioritize attacks on Shiites, and, after that, the monarchy's forces, before striking at "the Crusaders."
In the early days of Syria's war, Saudi leaders were accused of turning a blind eye to citizens who were joining the fight, some of them at the urging of ultraconservative clerics. But when Islamic State fighters started making sweeping gains there and in Iraq, there were signs that the monarchy was growing worried about blowback at home.
The late King Abdullah publicly chastised the country's religious scholars for "laziness" because of their silence about the group's atrocities. His government enacted a series of measures last year criminalizing the provision of any support to terrorist groups and making participation in foreign conflicts punishable by up to 20 years in prison.
U.S. officials, who have been critical of what they considered Saudi Arabia's inadequate efforts to counter terrorist financing, say the kingdom is now cracking down on wealthy individuals and charitable foundations accused of funneling funds to extremists. Saudi fighter jets have taken part in the U.S.-led air campaign against Islamic State, one of them piloted by a son of the new king, Prince Khaled ibn Salman. The country also co-chairs with the United States and Italy the coalition's efforts to disrupt the group's funding.
Regional experts credit the country's more forceful counter-terrorism posture to its interior minister, Prince Mohammed bin Naif, who survived an assassination attempt by an Al Qaeda suicide bomber in 2009 and was recently elevated to crown prince.
Mohammed led efforts to crush a previous uprising by Sunni extremists who view the monarchy's close ties with the U.S. as a betrayal of Islam and reject its claim to preside over Mecca and Medina. Between 2003 and 2006, Al Qaeda militants who had taken part in a Saudi-backed war to drive Soviet troops out of Afghanistan in the 1980s unleashed a wave of deadly bombings, shootings and kidnappings in the kingdom.
"This was Saudi Arabia's 9/11, in terms of the way it mobilized the government to go after terrorist activity," said Lori Plotkin Boghardt, a former U.S. intelligence analyst at the Washington Institute for Near East Policy.
Saudi authorities responded by arresting thousands of militants, driving them underground or into neighboring Yemen, now home to what is considered Al Qaeda's most dangerous affiliate.
At the urging of its Western allies, the Saudi government put in place new financial regulations and controls. A senior U.S. Treasury Department official, who asked not to be identified in discussing counter-terrorism operations, said wealthy Saudi donors remain an important source of funding for extremist groups. But he said it was unfair to accuse the government of condoning such activity.
Last month, the two governments announced that they were imposing sanctions on Al Furqan Foundation Welfare Trust, a Pakistan-based charity that is accused of channeling funds to Al Qaeda and other groups. U.S. officials hailed the joint action as evidence of Saudi commitment to fighting illicit finance.
In addition to going after terrorists and their backers, Saudi officials say, they are trying stamp out their "deviant" ideas. The government has cracked down on incendiary sermons in mosques, fired teachers accused of spreading extremism in the classroom and recruited religious leaders to help counter militant rhetoric online. It has also developed an intensive program to rehabilitate convicted terrorists through religious re-education, psychological counseling, job training and help starting a business or getting married.
Badr, who had sought to join the jihadist movement in Iraq and Syria, instead was enrolled at a de-radicalization center on the outskirts of Riyadh and has since renounced any notion of fighting abroad.
As part of the program, Badr spent hours debating the finer points of jihad with counselors at the Mohammed bin Naif Care and Rehabilitation Center, a complex of sand-colored buildings with grassy courtyards, an art studio and an Olympic-size pool.
"They told us about the teachings of the prophet Muhammad," he said. "His neighbor was a Jew, but he didn't kill him or fight him. Such things brought some sense to my mind."
Badr has now returned to his wife and children, runs a construction firm and preaches at a local mosque.
But the battle is hardly won: Some of the suspects rounded up in recent months were graduates of the de-radicalization program.
A poll commissioned by Boghardt's institute in September found that just 5% of Saudis rated Islamic State positively. But that, she noted, is still more than half a million people.