When the U.S. returned former al Qaeda operative Khalid al Jihani to Saudi Arabia after more than three years in prison in Guantanamo Bay, Cuba, he was ready to rejoin the terror group.

Instead, the Saudi government put him in its program aimed at de-radicalizing former jihadists before they are released back into society.

The monthslong program, at a secured compound in Riyadh, teaches religion to former jihadists with a focus on rejecting violence. It helps men find jobs and sometimes even a wife. Officials call residents “beneficiaries,” and the rehabilitation compound features a swimming pool and an art-therapy center.

Mr. Jihani was among the first to join the program, in 2006. He says it saved his life. He is now married—the government helped pay for the wedding—and works for a utilities company, a job Saudi authorities helped arrange.