The man accused of carrying out a bomb attack in New York City’s subway system was influenced by the sermons and writings of a radical Muslim preacher, Bangladeshi officials said Wednesday in the hours before the man was expected to have his first court appearance in the U.S.

Akayed Ullah, a Bangladeshi immigrant living in Brooklyn, had asked his wife in Bangladesh to read the writings and listen to the sermons of Moulana Jasimuddin Rahmani, the currently imprisoned leader of a banned group called Ansarullah Bangla Team, said Monirul Islam, a top official of Bangladesh’s counterterrorism department.

The group has been linked to killings and attacks on secular academics and atheist bloggers in Bangladesh. Rahmani is serving time in prison for his involvement in the killings.

The wife was questioned in Bangladesh and told investigators that her husband discussed Rahman’s writings with her during his last visit home, Islam said.

Ullah, 27, was expected to make his first court appearance Wednesday in New York, where he is in a hospital being treated for burns from a pipe bomb he strapped to his body and detonated in a pedestrian tunnel linking two busy subway stations.

Prosecutors in New York said that after his capture, Ullah told interrogators he was on a mission to punish the U.S. for attacking the Islamic State group.

“His motivation,” Acting U.S. Attorney Joon Kim said, “was not a mystery.”

Investigators found bomb-making materials in his apartment. They said he carried out the attack after researching how to build a bomb a year ago and planned his mission for several weeks. The bomb was assembled in the past week using fragments of a metal pipe, a battery and a Christmas tree light bulb, along with the metal screws, authorities said.

The defendant “had apparently hoped to die in his own misguided rage, taking as many innocent people as he could with him, but through incredible good fortune, his bomb did not seriously injure anyone other than himself,” Kim said.

He was charged with providing material support to a terrorist group, use of a weapon of mass destruction and three bomb-related counts. He could get up to life in prison.

Relatives and police said Ullah last visited his wife and newborn son in Bangladesh in September, after which he returned to the United States.

Counterterrorism officials questioned the wife and her parents before releasing her Tuesday night, Islam said, adding that investigators were currently questioning his brother-in-law and also planned to question any known close associates.

Ullah’s wife, Jannatul Ferdous, told ABC News in a brief interview conducted through the closed door of her home in Dhaka, Bangladesh, that she had never heard her husband speak negatively of the U.S. She said when she spoke to him by phone the morning of the bombing, he gave no indication of what he planned to do.

With a tragedy averted and a growing certainty that he acted alone, attention turned to how best secure New York City’s vast public transportation system and the daunting task of identifying those eager to do it harm.

The security “requires every single member of the public’s help,” said New York Police Commissioner James O’Neill. “It requires their vigilance.”

There also was political fallout, heightened by news that Ullah had taunted President Donald Trump on Facebook with a post that read, “Trump you failed to protect your nation.”

In reaction to the bombing, the president demanded a tightening of immigration rules that allowed Ullah to enter the country in 2011 on a visa available to certain relatives of U.S. citizens. Less than two months ago, an Uzbek immigrant who came to the U.S. through a visa lottery was accused of killing eight people in New York by mowing them down with a truck along a bike path.