Authorities, aided by technology, tips and luck, wrapped up a tension-filled weekend with the arrest Monday of a man suspected of setting off homemade bombs in New York and New Jersey that injured 29 people.

Ahmad Khan Rahami, a 28-year-old man and the target of an hourslong manhunt across the two states, was shot and injured in a gunbattle with police from Linden, N.J., where he was spotted sleeping outside a bar. Two police officers suffered minor injuries in the firefight.

Mr. Rahami, a naturalized U.S. citizen from Elizabeth, N.J., is suspected of planting bombs in four locations, beginning with an explosion Saturday morning near the starting line of a 5K race in Seaside Park, N.J. No one was hurt, but a blast that night in New York City injured 29 people. A third bomb found nearby failed to detonate, and five pipe bombs were found in an abandoned backpack Sunday by passersby near the train station in Elizabeth.

No motive has been cited by authorities who said Monday they were seeking any accomplices but believed Mr. Rahami had acted alone. The suspected bomber, shown after his arrest on TV strapped to a stretcher and loaded into an ambulance, was in surgery Monday. He was expected to recover from arm and leg wounds.

Prosecutors in New Jersey charged Mr. Rahami late Monday with the attempted murder of police officers in the shootout. Those charges are likely to keep him in custody while federal prosecutors in New York and New Jersey prepare terrorism charges.