LINDEN, N.J. — A New Jersey police officer responding to a call about a hoodied vagrant curled up asleep in a bar doorway roused him and quickly recognized the bearded face of the suspect in the weekend bombings in New York City and New Jersey.

Ahmad Khan Rahami — identified in an FBI bulletin just hours earlier — pulled a gun, shot the officer and triggered a running gunbattle in the street that ended with the suspect wounded and in custody Monday, authorities said.

The bloodied man was loaded into the back of an ambulance, just 50 hours after the first blast that started it all.

The suspect, 28, a naturalized U.S. citizen from Afghanistan who lived with his Muslim family in Elizabeth, New Jersey, underwent surgery for a gunshot wound to the leg as authorities began drawing up charges in a case that spread fear across the New York area and revived anxiety about homegrown terrorism.

New York Mayor Bill de Blasio said officials have every reason to believe the series of bombings “was an act of terror,” though investigators said an exact motive isn’t yet clear.

With the arrest, officials said they have no indication there are more bombs or suspects to find, though they cautioned that they are still investigating.

Still, after a whirlwind investigation that put the suspect in custody in just two days’ time, “I’m a lot happier today than I was yesterday,” New York City Police Commissioner James O’Neill said.

The probe started when a pipe bomb blew up Saturday morning in Seaside Park, New Jersey, before a charity race to benefit Marines. No one was injured.

Then a shrapnel-packed pressure-cooker bomb similar to those used in the Boston Marathon attack exploded Saturday night in New York’s Chelsea section, wounding 29 people, none seriously. An unexploded pressure-cooker bomb was found blocks away.

Late Sunday night, five explosive devices were discovered in a trash can at an Elizabeth train station. Investigators said they are still gathering evidence and have not publicly tied the earlier suspect to those devices.

Late Monday, the suspect was charged in New Jersey with five counts of attempted murder of police officers in connection with the shootout and was held on $5.2 million bail. Federal prosecutors said they were still weighing charges over the bombings.

The suspect lived with his family above their fried-chicken restaurant in Elizabeth, and his relatives have clashed with the city over closing times and noise complaints they said were tinged with anti-Muslim sentiment. A childhood friend, Flee Jones, said the suspect had become more religious after returning from a trip to Afghanistan several years ago. Still, some of the family restaurant’s customers said that while he was devout, he was more likely to talk about his interest in cars than to mention faith.

William Sweeney Jr., the FBI’s assistant director in New York, said there were no indications the suspect was on law enforcement’s radar at the time of the bombings.

Authorities zeroed in on him as the potential bomber after a fingerprint and DNA obtained from one of the New York sites and “clear as day” surveillance video from the bombing scene helped identify him, according to three law enforcement officials who spoke on condition of anonymity because they were not authorized to discuss the case.

Linden Mayor Derek Armstead said the break in the case came late Monday morning, when a bar owner reported someone asleep in his doorway.

After an officer arrived and recognized the suspect, he shot the officer, who was saved by his bulletproof vest, authorities said. More officers joined in a gunbattle that spilled into the street.

Another police officer was grazed by a bullet. Authorities said neither officers’ injuries were life-threatening.