WASHINGTON — No one knew it at the time, but Al Qaeda’s ability to strike in the West was severely damaged when a skinny onetime altar boy who grew up on Long Island stumbled into a Pakistani checkpoint in 2008, attacked a police officer and was detained.

Within days, F.B.I. agents had flown to Pakistan and were grilling the young man, Bryant Neal Vinas. He told them that he had consulted for Qaeda leadership on spectacular plans to blow up the Long Island Rail Road. Osama bin Laden wanted to turn him into a recruiting poster.

Mr. Vinas kept talking to the F.B.I. agents, and to federal prosecutors back in New York. He talked for the next eight years, taking part in 100 interviews, reviewing 1,000 photographs and assisting in more than 30 law enforcement investigations. Mr. Vinas, who had once volunteered to become a suicide bomber, turned on Al Qaeda with devastating effect.

The extraordinary assistance from Mr. Vinas, now 34, created a dilemma for the federal judge deciding his fate last week. The judge had to decide how to punish a criminal who had demonstrated such a capacity for evil but who had also helped deliver a crushing blow to the terrorists responsible for the Sept. 11, 2001, attacks.