For most of his 20s, all Badr al-Enezi could think about was becoming a jihadi fighter. After getting in touch with former Guantanamo Bay prisoners who had returned to militancy, he began plotting how to take up arms.

Instead, he was caught by Saudi authorities and spent six months in prison. His next six months in detention were far different: He dabbled with art therapy, played soccer and enjoyed perks like an Olympic-size pool and a sauna at a rehab center for convicted extremists.

Gourmet-style meals were prepared for him at the palm-tree-lined complex on the outskirts of the Saudi capital, Riyadh, and his laundry was taken care of. He was treated "like a brother," he says.

Equally important, he was challenged to think differently about Islam.

And now, after successfully completing the de-radicalization program and renouncing any notion of fighting abroad, he serves as a mentor for new entrants to the center, named after Saudi Arabia's powerful interior minister, Crown Prince Mohammed bin Nayef.

"What is the secret? It is that the ideas we carry cannot be cured by weapons only. It also requires an ideological cure," the 30-year-old says of the facility, which in many ways serves as the center-piece of Saudi Arabia's counter-terrorism strategy.

As the kingdom faces a new domestic threat from the Islamic State group that has killed 40 Saudi civilians and security personnel since November, it is revving up the groundbreaking program, which rehabilitates extremists through months of indoctrination by moderate Islamic clerics, sociologists and psychologists.

The effort is complicated by the kingdom's regional competition with Shiite rival Iran, which has stoked anti-Shiite rhetoric from hard-line Saudi clerics and fueled attacks on the country's Shiite Muslim minority, viewed by Sunni extremists like the Islamic State group as apostates.

Across the kingdom, Saudi officials and commentators slam Iran as an expansionist power that seeks to dominate the region, but conservative clerics take it even further, using language that is often laced with derogatory references to Shiites in general. In sermons and on Twitter, these clerics, who follow an ultraconservative Sunni doctrine known as Wahhabism, refer to Shiites as "rafideen," an Arabic slur for "rejectionists."

They condemn Shiite rituals, like praying at the tombs of revered figures, as an aberration of Islam and accuse Shiites of being faithful to hard-line clerics in theocratic Iran.

When 20-year-old suicide bomber Saleh bin Abdelrahman al-Qashimi unleashed the deadliest attack in the kingdom in more than a decade, targeting a Shiite mosque in eastern Saudi Arabia last month, his uncle blamed hard-line Wahhabi clerics for encouraging young men like his nephew toward extremism.

"They plant the seed in their minds," Mohammed Abdelrazzak al-Qashimi said of his nephew, who had disappeared a year before carrying out the May 22 attack, which killed 22 Shiite worshippers commemorating the birth of a revered saint.

That bombing, and an attack a week later that killed four people outside a large Shiite mosque in the eastern city of Dammam, were claimed by the Islamic State group. Residents in eastern Saudi Arabia, home to most of the country's Shiites, erected a banner with screenshots of 11 Wahhabi preachers and their anti-Shiite tweets. "These are the real killers," it read.

For many Saudi Shiites, the attacks, which began in November when eight worshippers were gunned down by alleged Islamic State militants, have come as no surprise. For nearly three years, clerics across the Gulf urged young men to join in jihad and purge Syria of its Iranian-backed government — sermons that helped draw more than 2,500 Saudis to fight alongside Sunni rebels trying to topple President Bashar Assad. That was until last year, when the kingdom decreed it illegal to fight jihad abroad or encourage it.

The Interior Ministry says around 650 fighters have since returned home, many bringing with them skills learned on foreign battlefields. So the Islamic State group changed tactics. It called on its Saudi supporters to carry out attacks inside the kingdom, which is custodian to Islam's holiest sites in Mecca and Medina.

For this new generation of home-grown extremists, the Islamic State group's ideology is attractive because its fighters are on the ground battling Iranian-backed militias in Syria and Iraq, says Abdulrahman al-Hadlaq, director of ideological security at the Interior Ministry and a founder of the rehab center.

The militant group, which was once al-Qaida in Iraq, "tricked a lot of youth," who saw them as the only force taking on the Shiite militias, he says, adding that his agency was revising its strategies to counter the dangers posed by the Islamic State group.

A key element of the kingdom's counter-terrorism arsenal is the Mohammed bin Nayef Center for Advice, Counseling and Care, as the rehab center is formally known.

Founded in 2007 by the prince whose name it bears — himself the target of several assassination attempts — its aim was the rehabilitation through religious re-education and psychological counseling of militants responsible for an earlier wave of al-Qaida bombings, shootings and kidnappings from 2003-2006.

With hundreds of militants filling up the kingdom's prisons, the center's focus was on trying to prevent those who had served their sentences from taking up arms again. It has treated some 3,000 men convicted of terrorism-related crimes, including all those released to Saudi custody from Guantanamo Bay, and claims a success rate of 87 percent.

Of the 13 percent, or roughly 390, who returned to militancy, half have been rearrested. Several turned up in Yemen to lead the local al-Qaida branch there.

At the center, inmates — called "beneficiaries" by staff — are housed in a complex of low-rise buildings, whose resort-like appearance is belied by the concrete walls, barbed wire and armed guards that surround it. Contact with family is encouraged, and participants are given access to private, fully-furnished apartments for conjugal visits with spouses.

If the center's team of experts deems an inmate mentally fit for release, they help him find a job, rent a house, buy a car and assimilate back into society.

Speaking to The Associated Press in front of psychologists at the center, al-Enezi said the program, which he completed in 2012, helped him understand religious doctrine through a different prism from what he'd learned online.

Clerics explained the Quran to him in a way that led him to believe whoever fights in jihad abroad is "serving a foreign agenda."

John Horgan, author of "The Psychology of Terrorism," says the Saudis took the idea of de-radicalization seriously and used creative techniques at a time when the West was increasingly relying on torture and drone strikes.

However, he says many see the Saudis as hypocritical when claiming moral high ground on counterterrorism efforts because they haven't prevented citizens from joining extremist groups in the first place.

"Some critics would say that this isn't true de-radicalization, this is just a diversion. It's smoke and mirrors," Horgan says. "What I've seen so far is that it's just a token gesture. It's very good for the optics and very good for public relations."

Mohammed al-Nimr, whose brother is an outspoken Saudi Shiite cleric, says changing the mindset of young men through the rehab program is not enough. An overhaul of the education system is needed as part of the counterterrorism strategy, he said.

The turn to the Islamic State group by young Saudis "is a result of the ideological terrorism that is taught in our schools," he says. "They do not teach anyone to respect people with contrary views. They use religious justification for the killing of these people."

___

Follow Aya Batrawy on Twitter at www.twitter.com/ayaelb .