The would-be New York suicide bomber mocked Donald Trump in a Facebook post just hours before his attack on Monday, and also left behind a chilling handwritten note in his home.
Police have scoured the Brooklyn residence of accused terrorist Akayed Ullah, 27, as they try to piece together why the Bangladeshi immigrant detonated a homemade pipe bomb inside one of New York City's busiest subway corridors during rush hour.
"Trump you failed to protect your nation," the Facebook post said, according to court papers filed on Tuesday.
Investigators also found that Mr Ullah had added multiple handwritten notations to his passport, including the chilling threat: "O America, die in your rage."
Ullah has been hit with five charges after Monday morning's attack: supporting a terrorist organisation, use of weapons of mass destruction, bombing a place of public use, destructing property with an explosive and using a destructive device in a crime of violence.
A 10-page criminal complaint filed in a New York federal court on Tuesday alleges that Ullah detonated an improvised explosive device inside the Port Authority Bus Terminal subway station, in Midtown Manhattan.
He had strapped a homemade pipe bomb to his body using plastic cable ties. He packed the metal pipes with explosives and metal screws in order to inflict "maximum damage", court papers show. The bomb was detonated via a Christmas tree light bulb and wires powered by a nine-volt battery in his pants pocket.
The court papers draw on CCTV cameras pointed at the passageway that connects the Port Authority and Times Square stations to show that Ullah was the perpetrator.
He was the only person seriously injured in the blast, which happened about 7.20am.
The suspect was taken to Bellevue Hospital after the bombing where he told police, "I did it for the Islamic State".
He said he built the pipe bomb inside his Brooklyn home about a week before carrying out the attack, after he accumulated the necessary materials over the three weeks prior.
The bombing was inspired, in part, by the US's policies in the Middle East.
"One of Ullah's goals in carrying out the December 11 attack was to terrorise as many people as possible," the court papers allege.
"He chose to carry out the attack on a workday because he believe that there would be more people."
Ullah, who came over from Bangladesh about seven years ago on a family union visa, was radicalised on US soil, beginning in about 2014.
"Ullah viewed pro-ISIS materials online including a video instructing, in substance, that if supporters of ISIS were unable to travel overseas to join ISIS, they should carry out attacks in their homelands," the court documents say.
"He began researching how to build IEDs (improvised explosive devices) on the internet approximately one year ago."
On the morning of the attack, Ullah wrote an anti-Trump message on Facebook as well as another post designed to show that he had carried out the attack in the name of Isis.
Only three other people were hurt in Monday's incident and their injuries were minor, including headaches and ringing in the ears from the explosion.
The bombing came six weeks after another Isis-inspired immigrant killed eight people when he drove a vehicle down a New York bike path.
Accused terrorist just had baby
Counter-terrorism officers in Bangladesh have questioned Ullah's 25-year-old wife, whom he married in 2016 and visited in September after the birth of their son, officials said.
Police raided the family home in Dhaka, but neither Ullah's wife, Jannatul Ferdous Piya, nor her father are under any suspicion, officer Saiful Islam told AFP.
Mofazzal Hossain, caretaker of the family apartment in Dhaka, described Ullah as "pious and a gentleman".
"He used to pray in the local mosque five times a day. He would urge us to pray and do good work," Hossain told AFP.
Trump, who has clamped down on immigration since taking office in January, called for tougher US immigration rules on Monday, saying the current policy allows "far too many dangerous, inadequately vetted people to access our country".
He has called for the elimination of programs that allowed Mr Ullah and bike path attack suspect Sayfullo Saipov to move to the US, and called for a merit-based immigration policy.
New York mayor Bill de Blasio, a strident Trump critic, said the President's criticism was misplaced, stressing that Ullah would not have been allowed into the country if his sponsors were not of "good standing".
The family issued a statement through the Council on American-Islamic Relations saying they were "heartbroken" by the attack and the allegations against Ullah.
The New York Times reported that Ullah prayed regularly at the Masjid Nur Al Islam mosque and, from 2012 to 2015, held a licence to drive hire vehicles.
A businessman neighbour told the newspaper that he had unpleasant encounters with Mr Ullah in recent years, largely about parking and complaints that his family used to block the driveway.