A Bangladeshi student who came to the U.S. intending to commit jihad was sentenced Friday to 30 years in prison after pleading guilty to terrorism charges for trying to blow up the Federal Reserve Bank in New York. The plot was a phony operation engineered by undercover agents.

“I’m ashamed. I’m lost. I tried to do a terrible thing. I alone am responsible for what I’ve done. Please forgive me,” Quazi Mohammad Rezwanul Ahsan Nafis said before his sentence was handed down in Brooklyn federal court.

He begged for leniency and forgiveness, apologizing to the judge, the United States, New York City and his parents and said he no longer believed in radical Islam. “I’m really grateful that the agents saved me,” he said.

Nafis was arrested after he tried to detonate a phony 1,000-pound truck bomb outside the bank in October. He pleaded guilty in February to attempting to use a weapon of mass destruction and attempting to provide material support to al-Qaida.

In sentencing Nafis to the minimum, Judge Carol Bagely Amon said she believed the 22-year-old was remorseful. He had faced up to life in prison.

“It does not change the fact he was sentient when he engaged in efforts to destroy the Federal Reserve and the people inside,” Amon said. “He knew what he was doing.”

In a five-paged typed letter, Nafis tried to explain to the judge how he turned to radical Islam, telling her he had a stammering problem and no real friends in his native country. His lawyer, Heather Cesare, said he was beaten by his parents and kept sheltered.

“For being a very simple guy I fall for people very easily,” Nafis wrote, chronicling how he fell in with a group of radical students at his university in Bangladesh. “I was becoming religious but never realized that I was misguided slowly but surely with the wrong teachings of Islam.”

He became despondent over a girl and wanted to commit suicide, which is illegal in Islam, and turned to jihad instead, he said. Nafis came to the United States in January 2012 enrolled at a Missouri college to study cybersecurity. But he was instead intending to do something sinister, prosecutors said.

“When the defendant was packing to come to the United States, he made sure to include his bomb instructions,” Assistant U.S. Attorney James Loonam said.

He left the school and came to live with a relative in New York. Authorities say Nafis began using Facebook and other social media to seek support for a terrorist attack. One of his contacts turned out to be a government informant who notified authorities.

While under investigation, Nafis spoke of his admiration for Osama bin Laden and talked of writing an article about his plot for an al-Qaida-affiliated magazine, though he was not affiliated with al-Qaida. He also talked about wanting to kill President Barack Obama and cased the New York Stock Exchange before deciding on the bank as a target.

As the plot progressed, Nafis selected his target, drove a van loaded with dummy explosives to the door of the bank and tried to set off the bomb from a hotel room using a cellphone he thought had been rigged as a detonator, authorities said. No one was ever actually in danger because the explosives were fakes provided by the government.

Loonam said the undercover did not push Nafis. The plot was, “the defendant’s plan, the defendant’s target, the defendant’s actions.”

His parents, who are middle-class professionals living in Dhaka, could not make the trip from Bangladesh.

Nafis said quietly in court he had broken his parents’ hearts.

“I’m terribly sorry for what I’ve done,” he said.