On the surface, Akayed Ullah seemed to be an ordinary member of a Bangladeshi enclave in Brooklyn. He often prayed at a mosque in an unassuming brownstone in the Kensington section of the borough, where a few thousand of his countrymen reside. Like many immigrants in New York, he made his living — at least for a while — driving for a car service.

But on Monday morning, Mr. Ullah, 27, strapped a pipe bomb to his body and set out to detonate it in a Times Square subway station, the police said, not only causing chaos among crowds of commuters, but also leaving behind a trail of mystery that baffled those who knew him.

“He was a good guy,” said Mohammad Yousuf, a cabdriver who prayed with Mr. Ullah at the mosque. “I can’t believe he would do anything like this.”