The man who the police said sowed terror across two states, setting off bombs in Manhattan and on the Jersey Shore and touching off a furious manhunt, was tracked down on Monday morning sleeping in the dank doorway of a neighborhood bar and taken into custody after being wounded in a gun battle with officers.

The frenzied end came on a rain-soaked street in Linden, N.J., four hours after the police issued an unprecedented cellphone alert to millions of people in the area telling them to be on the lookout for Ahmad Khan Rahami, 28, who was described as “armed and dangerous.”

Even as the remarkably swift arrest eased fears across the region, investigators were still in the earliest stages of trying to determine what provoked the attacks, why a street in Chelsea was one of the targets and whether the bomber was aided by others. While investigators have been focused on Mr. Rahami’s actions immediately before and after the bombings, they were also working on Monday to trace his activities and travel in both recent months and years.

One law enforcement official said that the bomb technicians involved in the investigation believed that Mr. Rahami constructed all the devices and that his handiwork raised the possibility that he had received training from someone with experience building improvised explosive devices.