NEW YORK (AP) — A man who plotted to bomb New York City's subways, then switched sides after his arrest and spent nearly a decade helping the U.S. identify and prosecute terrorists, was rewarded for his help Thursday with a sentence of 10 years in prison, effectively time he has already served.

Najibullah Zazi, a 33-year-old naturalized U.S. citizen who became radicalized and received explosives training from al-Qaeda after traveling to Pakistan in 2008, had faced the possibility of life in prison. But federal prosecutors said that after his arrest in 2009, Zazi provided “extraordinary” assistance to U.S. counterterrorism authorities.

"I have no doubt you saved a life," U.S. District Judge Raymond J. Dearie told Zazi during the sentencing hearing.

Zazi apologized and asked for forgiveness.

"I'm sorry for all the harm I have caused," he said. He referred to the crime as a "horrific mistake."

The 10-year term means Zazi could be released from prison soon. He has been in custody for a decade.

The terrorist organization recruited Zazi, who spent his teenage years and young adulthood living in Queens, to carry out a "martyrdom operation" on U.S. soil. The mission called for rush-hour suicide bombings on subway lines, timed to occur during the Muslim holy month of Ramadan and the eighth anniversary of the Sept. 11 terror attacks.

The plot, foiled by federal authorities, represented "one of the most serious terrorist threats to our nation" since 9/11, then-Attorney General Eric Holder said.

Federal sentencing guidelines called for Zazi to spend the rest of his life behind bars after his 2010 guilty plea.

But prosecutors credited Zazi for cooperation that included implicating his two best friends in the subway plot and providing “critical intelligence and unique insight regarding al-Qaeda and its members.”

Zazi’s cooperation included meeting with the government “more than 100 times, viewing hundreds of photographs, and providing information that assisted law enforcement officials in a number of different investigations.”

He testified at the 2015 trial of Abid Naseer, a Pakistani national convicted of leading an al-Qaeda plot to bomb a shopping mall in Manchester, England, and against one of his coconspirators in the thwarted subway plot, Adis Medunjanin, who was convicted and sentenced to life in prison.

“Zazi’s assistance came in the face of substantial potential danger to himself and his family,” Assistant U.S. Attorney Douglas M. Pravda wrote in the court filing. “By aligning himself with the government against [al-Qaeda], Zazi assumed such a risk.”

The third man charged in the subway plot, Zarein Ahmedzay, offered similar assistance to federal authorities and was sentenced in December to 10 years — essentially time served.

Zazi’s attorney and federal prosecutors declined to comment ahead of the sentencing, which is scheduled for 2:30 p.m. before U.S. District Judge Raymond J. Dearie.