Or was he following his own heart, reflecting some sort of inner struggle as he headed toward his first known act of violence and self-destruction?

A few weeks after his trip, federal investigators said, Mr. Ullah, 27, returned to Brooklyn and began building a bomb out of matchheads and a piece of pipe he found at a construction site. He detonated it on a busy Monday morning, Dec. 11, in a Manhattan subway station, wounding himself and a few passers-by but doing far less damage than he could have. He was apprehended on the spot.

From a bed in Bellevue Hospital Center on Manhattan’s East Side, he has been cooperating with investigators, saying he was inspired online by the Islamic State to strike against the United States for its policies in the Muslim world. Charged with several terrorism-related offenses, he may never get out of jail. In many ways, his is an open-and-shut case.

Image Mr. Ullah in an ambulance after being apprehended in New York.

But extensive interviews with more than a dozen friends, relatives and acquaintances, in Bangladesh and the United States, still leave a hole as to why Mr. Ullah did this. He comes across as impulsive, angry, riveted to militant social media and outraged by injustices inflicted on Muslims.

He was also described by several people who know him well as loving and giving. And he did not seem hopeless, a classic characteristic of people about to take their own lives, nor was he isolated. He was close to his childhood family — his mother and siblings — and he was building a new one.