The Bangladeshi immigrant arrested in a botched suicide bombing in the New York subway mocked U.S. President Donald Trump on Facebook on his way to carry out the attack, writing "Trump you failed to protect your nation," authorities said Tuesday as they brought federal charges against him.

Akayed Ullah, 27, was accused of detonating a pipe bomb strapped to his body in an underground passageway between Times Square — the city's busiest subway station — and the bustling Port Authority Bus Terminal. The device did not fully detonate, and Ullah was the only one seriously hurt in the Monday morning attack.

At the hospital where he was taken with burns on his hands and torso, he told officers, "I did it for the Islamic State," according to the criminal complaint. Also, a search of his Brooklyn apartment turned up a passport in his name, scrawled with the words "O AMERICA, DIE IN YOUR RAGE," authorities said.

He was expected to appear before a magistrate, though it was not immediately clear if he was well enough to go to court. His court-appointed lawyer did not immediately return a message seeking comment.

'Hate-filled heart'

At a news conference, Acting U.S. Attorney Joon H. Kim said Ullah picked a rush hour on a weekday to maximize casualties in his quest "to kill, to maim and to destroy."

Ullah, "with a hate-filled heart and an evil purpose," carried out the attack after researching how to build a bomb a year ago and planned his mission for several weeks, Kim said.

The bomb was assembled in the past week using fragments of a metal pipe, a battery and a Christmas tree light bulb, along with metal screws as shrapnel, authorities said. They said it was strapped to his body with wires and zip ties.

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.

Ullah 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.

NYC Subway Explosion

Acting U.S. Attorney for the New York Joon H. Kim said investigators found a 'chilling' note during a search of a Brooklyn home Monday. (Seth Wenig/Associated Press)

According to the court papers, Ullah started to become radicalized in 2014 and began researching how to build a bomb after watching ISIS propaganda materials online, include a video urging supporters to carry out attacks in their home countries. Law enforcement officials said there was no evidence he had any direct contact with the militants.

He taunted Trump on Facebook just before the attack, authorities said.

Trump wants immigration rules tightened

In reaction to the bombing, the president demanded a tightening of immigration rules.

Ullah entered 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.

"We're going to end both of them — the lottery system and chain migration. We're going to end them fast," Trump said at the White House.

Later Tuesday, during the daily White House news briefing, immigration chief Francis Cissna echoed Trump's comments saying the administration believes "that is not the way that we should be running our immigration program."  

NYPD

In this undated photo posted by NYPD commissioner James P. O'Neill, an officer and a police dog patrol a corridor in the New York City subway system near the site of Monday's bomb attack. (James P. O'Neill/Twitter)

Ullah lived with his father, mother and brother in a Brooklyn neighbourhood with a large Bangladeshi community, residents said. He was licensed to drive a livery cab from 2012 to 2015, but the licence was allowed to lapse, officials said.

'Not on our radar'

He "was living here, went through [a] number of jobs, was not particularly struggling financially or had any known pressures," John Miller, the New York Police Department's deputy commissioner for counterterrorism, said Tuesday on CBS. He added that Ullah "was not on our radar at NYPD, not on the FBI radar."

Overseas, Bangladesh counterterrorism officers questioned Ullah's wife and other relatives, officials said. Relatives and police said Ullah last visited Bangladesh in September to see his wife and newborn son.

Ullah's uncle, Abdul Ahad, said his nephew mostly remained inside a small apartment in Dhaka's Hazribagh area when he recently visited Bangladesh.

"He went out of his residence to offer prayers at a nearby mosque," Ahad told The Associated Press.

He said Ullah arrived in Bangladesh on Sept. 8 and returned to New York on Oct. 22. 

"He stayed with his wife and six-month-old baby boy," he said, adding that Ullah was a quiet person who rarely socialized. 

Ahad said Ullah also returned to Bangladesh two years ago to get married and stayed for about three months. 

Ahad, Ullah's wife and her parents are being interrogated by officials from Bangladesh's counterterrorism and transnational crime department, said Abdul Mannan, an official involved in the investigation. 

Mannan said Ullah appeared to have no criminal record in Bangladesh and was not a known member of any militant group.

With files from Reuters and CBC News