Dina Temple-Raston was NPR’s counterterrorism correspondent for a decade and is now working on a series of shows about technology that will air on the network later this summer.

In January 2015, two brothers burst into the offices of Charlie Hebdo magazine in Paris and opened fire in an attack that decimated the editorial staff of a satirical newspaper whose only crime was lampooning Islam. The Hebdo shooting was only the beginning. By the end of the year, France had suffered a wave of attacks: a man wielding a knife in a Jewish community center in Nice, aborted strikes at a church and aboard a high-speed train, and then, in November, violent jihadists trained by the Islamic State fanning out across Paris, killing 130 people and wounding more than 350 in the worst terrorist attack in French history. The following spring, the violence spilled across the border into Belgium, where coordinated suicide bombings tore through the check-in area of the Brussels airport and a metro station. Nearly all of the young men implicated in those rampages had one thing in common: They were ex-convicts radicalized while in prison.

To understand how that happens, you just need to look at the numbers. Muslims make up about 6 percent of the total Belgian population but account for more than a third of its prison inmates. In France, though officials will tell you they do not ask inmates about their religion, the statistics are worse. Prison advocacy groups say that while Muslims are just 14 percent of the French population, they make up more than 60 percent of Frenchmen behind bars. With that in mind, it is easy to see how radicalization becomes an easy sell. Radical imams tell young inmates: Just look around you; all you see are Muslims here. Studies show that more than any other single factor, discrimination — not poverty — has a direct link to terrorism and violence.

In “Why Young Men: The Dangerous Allure of Violent Movements and What We Can Do About It,” Jamil Jivani seeks to explain why young men are so drawn to what appears to be senseless violence. By using his own experience as a touchstone, as the son of a mostly absent black father and a white mother, as a young man reared in a tough suburb of Toronto, Jivani makes a compelling case that radicalization grows out of marginalization.

Now a professor and activist, Jivani offers a compassionate analysis of sidelined youth and does so with a special authority — because he was one. “Growing up, I saw police officers as henchmen of the status quo seeking to keep me and people I cared about down,” he writes. On one occasion, an aggressive officer pulled over the family car and, at least in Jivani’s telling, provided “the first time I believed I was witnessing racism in action.” He watched his father grow docile as the officer questioned him. The family had done nothing, but that hardly mattered. The very fact that they were pulled over confirmed Jivani’s belief that he was the other.

“Waiting for the bus, walking home from school and hanging out at the mall . . . sometimes they stopped me to ask questions; other times they looked at me with suspicion or intimidation in their eyes. I attributed their behavior to racism. I saw whom they stopped and whom they didn’t.”

Jivani said his response was predictable: It began with resentment, matured into anger and eventually found its violent voice in the world of gangster rap that he and his friends embraced passionately. “I think we liked it so much partly because it reflected a certain anger we had within us,” he writes. “We were angry because we didn’t have fathers around, because our families didn’t have the money we wanted and because life at home was unstable and unpleasant. . . . And we didn’t have any role models to steer us away from it.”

Jivani sees a clear correlation — he actually writes that it was a causation — between the consumption of rap music and how he and his friends started to behave. They began fighting more at school. They began adopting some aspects of gang culture — bandannas, colors, even taking on gang names. “Being in the ‘hood’ as portrayed in Hollywood movies was my mentality,” he writes. “I felt that I was destined to suffer in a world that didn’t care about me. I simply didn’t know any other way to exist.”

Jivani describes how he spent most of his high school years trying to find a way around a system that he had been taught was rigged. He failed a literacy test in the 10th grade and was placed in remedial classes for the “illiterate.” He considered dropping out. The narrative unfurls like an inner-city tale we’ve heard before, and then it takes an unexpected turn: Jivani asked a friend to get him a gun and then discovered he couldn’t go through with the purchase. That moment offered not just a realization but a way out. “By facing the reality that I wasn’t cut out to be a gangster,” Jivani writes, he was able to reshape his life. He turned to education.

His story has a happy ending. Jivani finished college, attended Yale Law School and eventually began to work with nonprofits and policy organizations that help young men; the effort was focused on community policing and local jobs programs. He even traveled to Belgium and the Middle East to learn from existing programs that addressed these kinds of issues. “There were similarities between the Paris attackers and some of the young men I had grown up with in the Toronto suburbs; children of immigrants, living in a disadvantaged neighborhood,” he writes. “I wondered if ISIS’s success at recruiting young men in Europe was a more extreme example of what I had seen in my own life and that of my friends.”

His conversations with Belgian Muslims echoed those in my own reporting: Radical Islamists in France and Belgium nurse resentments born out of discrimination. Employers won’t hire young people who aren’t white. “You’re not Belgian if you look like this,” one student told Jivani, pointing to his own brown skin. Naturally, Jivani can not only sympathize, but truly empathize.

Jivani is a good writer, dissecting the dissonances of his youth and combining thoughtful inquiry with firsthand experience. The book is less successful in discussing what to do about young men and violence. Suggesting that additional mentoring programs and police reform will prevent others from falling into violent movements is hardly groundbreaking. Given the history of the problem and Jivani’s experience, one hopes he would have come up with something more innovative, a genius idea that grew out of his insider status, but maybe that is asking for too much. Young men and their attraction to violence is an issue we have been trying to puzzle out for some time. To expect Jivani to invent a magic remedy may be unfair.

His friend J.D. Vance, author of the best-selling “Hillbilly Elegy,” writes the book’s introduction (the two met at Yale), and it was a good choice: It reminds readers that what is most successful about “Why Young Men” is Jivani himself. His is an unlikely redemption story of a journey from the depths of marginalization to the national stage — he might be just the role model young men seeking to avoid the allure of violence need.

Why Young Men

The Dangerous Allure of Violent Movements and What We Can Do About It

By Jamil Jivani

All Points. 264 pp. $28.99