He was a high-school dropout from Queens who worked in a coffee cart in downtown Manhattan in 2006 when a friend handed him an audiotape of a radical Muslim cleric.

That was the start of a personal odyssey that sent the young man, Najibullah Zazi, to fight in Afghanistan. There a senior Al Qaeda official trained him to build bombs and sent him back to the United States, where he and two friends planned a suicide attack in the New York City subway system.

Mr. Zazi was arrested in 2009, and on Thursday his case came to an end when a federal judge, citing his cooperation with American authorities and his testimony at two trials, gave Mr. Zazi a 10-year sentence that his lawyers said could result in his release from prison within days.

The plot, which authorities called one of most dangerous terrorist conspiracies since the Sept. 11 attacks, was abandoned by Mr. Zazi and two of his former classmates from Flushing High School after they became fearful they were under scrutiny.