Sidna grew up in a poor neighborhood of Nouakchott called Toujanine. When I went there one evening in December, I found kids playing soccer at dusk in a wide dirt road. Goats rummaged through trash that filled a ditch about five feet from the front door of Sidna’s home. According to friends, neighbors and relatives, Sidna had a reputation as a scrappy kid. “Sidi wasn’t a thief, because thieves rob you and run,” one childhood friend told me. “Sidi took your watch or your T-shirt right in front of you.” By his midteens, Sidna was smoking hashish, drinking wine and hanging out with an older crowd. He liked to dance and earned the nickname Lambada. Besides robbing people, he also stole cars. Friends and law-enforcement authorities claim that he was involved in multiple rapes.

But his conscience apparently caught up with him by his late teens. He joined a friend at a mahadra — an Islamic seminary — outside Nouakchott. He spent several months there and, like many restless young men in the region, grew fond of listening to jihadist audio recordings, particularly those of Abu Musab al-Zarqawi, the leader of Iraq’s Al Qaeda franchise, that circulated around the mahadra.

“Why Zarqawi?” I asked the friend who took Sidna to the mahadra. “What made his sermons appealing?”

“Everyone in the Muslim world wants to see American tanks blown up and their troops killed,” he said. “But bin Laden and Zarqawi were the only ones actually doing it. Sidna admired them for that.”

Sidna returned home to Toujanine a changed, yet no mellower, person. As part of his Zarqawi-fueled indoctrination, he adopted the ideology of takfir, or excommunication, which some extremists use to justify violence against nonbelievers. He began converting some of his fellow gang members into militant Salafists. Sidna ordered his sisters to cover their heads, patrolled the neighborhood for unmarried couples walking together and spent long hours arguing with his father, a Sufi, during which times he called him an infidel. He told his younger brother that he wanted to wage jihad against the Americans. Then Sidna headed off to a training camp.

In the spring of 2006, Sidna traveled to a camp in northern Mali run by the G.S.P.C., the notorious Algerian-Salafi group. He prayed that those running the camp would send him to Iraq to fight against Americans. The invasion of Afghanistan, followed by the one in Iraq, attracted young men from all over North Africa eager to wage jihad against the United States. Fernando Reinares, the director of a program on global terrorism at Elcano Royal Institute in Madrid, says G.S.P.C. camps served as one of the main conduits of foreign fighters into Iraq. “They recruited individuals at the local level, trained them and then sent them to Iraq,” he said. European police reported a growing number of G.S.P.C. cells in major cities. In 2002, authorities in Italy claimed to have disrupted a G.S.P.C. plot in Bologna to bomb the Basilica of San Petronio, which has a 15th-century fresco of the Prophet Muhammad being tormented by demons in hell.

Sidna was disappointed when he reached the camp. The G.S.P.C. was in the midst of an overhaul. He found that the group was no longer looking for able-bodied young men to dispatch to Iraq, in part because of American pressure on North African leaders to clamp down on the migration of jihadists to Iraq. But it was also by choice. Now the G.S.P.C. had a new mission, to recruit non-Algerian militants to spread jihad south of Algeria.

Sidna fit into the group’s plans perfectly. The G.S.P.C.’s finances couldn’t keep pace with its ambitions, however. So G.S.P.C. leaders reached out to Zarqawi, who, until he was killed by American forces in Iraq in June 2006, enjoyed not only name recognition but also a seemingly endless pile of money. With Zarqawi as matchmaker, the G.S.P.C. courted Al Qaeda itself. After lengthy negotiations, bin Laden’s deputy, the Egyptian doctor Ayman al-Zawahiri, announced the “blessed union” between the G.S.P.C. and Al Qaeda on Sept. 11, 2006. He declared that the merger would be “a bone in the throat of American and French crusaders.” Months later, the G.S.P.C. proclaimed its new name: Al Qaeda in the Islamic Maghreb, or A.Q.I.M.