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.
“If you’re working off the premise that the guy made all these devices,” the official said, “then the guy is a pretty good bombmaker. And you don’t get that good on the internet.”
It could not be determined on Monday whether Mr. Rahami had a lawyer, and his father did not respond to questions from reporters waiting outside the family’s apartment.
Mr. Rahami and his family had traveled periodically to Pakistan, and on one trip, he stayed for nearly a year. A senior law enforcement official said that no evidence had yet been uncovered that he had received military training abroad.
The senior law enforcement official said agents with the Federal Bureau of Investigation were examining Mr. Rahami’s electronic devices as part of an effort to determine if he was inspired or directed by the Islamic State or any other terrorist organization.
Assistant Director William F. Sweeney, who heads the F.B.I.’s New York office, said investigators had not found any indication that there is a terrorist cell operating in the area or in the city, he said.
The arrest was the culmination of a sweeping, connect-the-dots manhunt that grew in urgency as the police and F.B.I. agents pieced together clues gleaned from both high-tech investigative tools and practiced detective work.
The weekend began with what seemed like an odd and troubling event, but one that hardly aroused widespread alarm.
At 9:30 a.m., three pipe bombs tied together blew apart a trash can just before the scheduled start of a Marine Corps run called Seaside Semper Five in Seaside Park, N.J.
Only one of the three bombs had detonated and no one was injured. The F.B.I. was brought in to investigate, but there was no indication about what would unfold 11 hours later.
Investigators believe that Mr. Rahami drove a car registered to his father into New York City shortly before the Chelsea blast erupted at 8:30 p.m.
In a review of surveillance video, the police later saw him near West 23rd Street and Avenue of the Americas wearing a backpack investigators believe contained one pressure cooker bomb. He was pulling a patterned duffle-type rolling bag that they believe contained another pressure cooker bomb and wearing a fanny pack on his left hip.
A short time later, a powerful explosion sent debris flying and shattered windows up and down the block. The bomb, filled with shrapnel and placed under a Dumpster on the busy crosstown thoroughfare, injured 29 people.
City streets were soon locked down and a tip to 911 led the police to a second device, the other pressure cooker bomb with a cellphone attached, four blocks to the north. Surveillance video collected by investigators would later show Mr. Rahami on West 27th Street, without his backpack but pulling the patterned bag and leaving it beside a mailbox.
But it would take hours to gather and analyze all of that video and zero in on Mr. Rahami as the man who left the bag behind.
All officials knew on Saturday night was that someone had deliberately placed bombs on a city street. Mayor Bill de Blasio was hesitant to call it an act of terrorism, and officials cautioned against linking the attack to the explosion in New Jersey.
The unexploded bomb found on West 27th Street, however, held critical clues. Once the police were able to remove it and examine it, they discovered a fingerprint that matched one in an arrest record for Mr. Rahami.
They also found similarities between the New York and New Jersey bombs, leading them to reverse their conclusion that they were not linked.
Most or all used old-style flip phones — an LG and a Samsung on the two Manhattan devices and an LG in Seaside Park — as timers, with Christmas-tree-style lights as initiators, the officials said. They said HMTD, an explosive compound, served as the detonator and a compound similar to a commercial explosive known as Tannerite served as the main charge in some devices.
Ahmad Khan Rahami, 28, the suspect in a bombing in the Chelsea neighborhood of Manhattan that injured 29 people Saturday night, was arrested in Linden, N.J.
Roughly 20 minutes after Mr. Rahami left the bag on West 27th Street, two men happened upon on the luggage, apparently unaware of its explosive contents. One of the men opened the bag, pulled out the bomb, which was inside a white plastic bag, and then left with the luggage. The authorities, who are eager to talk to the men, said that their handling of the device may have disabled it.
By Sunday, the authorities were monitoring addresses associated with Mr. Rahami. Increasingly confident that he was involved with the bombings, they made the decision to act when they saw a vehicle leaving one of those addresses.
The car was pulled over on the Belt Parkway near the Verrazano-Narrows Bridge in Brooklyn. Five people inside, some of them Mr. Rahami’s relatives, were questioned and later released.
Later on Sunday night, the police received a report of a suspicious package near a train station in Elizabeth, N.J.
The F.B.I., which responded, deployed a pair of robots to examine the bag and determined that it held five bombs, some of which were pipe bombs.
Around 12:30 a.m., the robots tried to clip a wire to disarm one bomb and accidentally detonated it. No one was injured.
The location of the bag was not far from where the Rahami family ran a restaurant, and before dawn on Monday, federal agents and local police officers were swarming a neighborhood of low-rise apartment buildings and small businesses.
They searched the restaurant, First American Fried Chicken, and addresses where Mr. Rahami was reported to have spent time.
It was 3:05 a.m. Anthony Rodriguez, who lives across the street from the restaurant, heard an officer yell: “Come down! Come down!”
The police stormed up the stairs that led to the two apartments above the restaurant. They brought down of the suspect’s brothers. Officers questioned them.
Officers also brought down a woman who looked about 30, draped in colorful shawls that did not cover her head, and a girl wearing pajamas. They were locked inside a squad car.
The suspect’s father came down about 20 minutes later, handcuffed and wearing only shorts.
As investigators realized that all of the attacks were linked and that the bombs reflected a certain level of sophistication, they worried that the bomber would grow desperate and do something even more drastic.
They decided to take the unprecedented measure of using New York City’s emergency notification system — typically for major weather events — to alert people in the region that a dangerous suspect was on the loose. Shortly after 7 a.m., millions of people in the region received the notification to be on the lookout for Mr. Rahami.
Even as the police scoured the area near the restaurant, Mr. Rahami was seeking shelter from the morning rain under a doorway of a bar, Merdie’s Tavern in Linden, which is next to Elizabeth, trying to catch some sleep.
Around 10:30 a.m. the owner of the bar spotted a man sleeping in the doorway, officials said.
Capt. James Sarnicki of the Linden Police Department told reporters that an officer approached the man, later identified as Mr. Rahami, and when he woke him, he saw that he had a beard resembling that of the man on the wanted poster.
The officer ordered him to show his hands, Captain Sarnicki said, but instead, he pulled out a handgun, shooting an officer in the abdomen; the bullet struck his vest.
“The officer returned fire,” he said. Mr. Rahami fled, “indiscriminately firing his weapon at passing vehicles.”
Other officers joined the chase, and Mr. Rahami was shot multiple times. At least one other officer was wounded during the confrontation.
Shortly after 11 a.m., Mr. Rahami was in custody, splayed out beside the street, hands cuffed behind his back and his shirt rolled up, officers standing over him with their weapons drawn.
Mr. Rahami, blood pouring from a wound in his shoulder and splattered on his face, was loaded onto a stretcher and taken to University Hospital in Newark.
Diego Jeronimo, 36, the owner of a store near where the gun battle unfolded, said he opened his front door and saw a police car parked lengthwise across the street, an officer with his back to him with his gun drawn using the car as a shield. He heard around five shots.
“Then it calmed down a little bit, then we hear seven shots, but they were more distant,” he said.
Shawn Styles, 30, who works at Linden Auto Body next door, said he saw numerous police vehicles whiz down the avenue.
“Then multiple, multiple shots,” he said.
By sundown, Mr. Rahami had been charged with seven counts, including five counts of attempted murder of a law enforcement officer, with bail set at $5.2 million. Mark Spivey, a spokesman for the Union County prosecutor’s office, said he did not know if Mr. Rahami had legal representation.