ELIZABETH -- The man suspected of planting bombs in New York City and New Jersey was charged Monday with trying to kill law enforcement officers, hours after he was captured following a shootout with Linden police, officials said.

Ahmad Khan Rahami, 28 (Photo: UCPO)

Ahmad Khan Rahami, 28, a naturalized citizen from Afghanistan who was living in Elizabeth, was charged with five counts of attempted murder of a law enforcement officer, according to the Union County Prosecutor's Office. Bail was set at $5.2 million. He also faces weapons-related charges.

The arrest came following a fast-moving manhunt across the region as local, state and federal law enforcement officers searched for Rahami. He is suspected of planting a pipe-bomb style device that detonated near a military charity run in Seaside Park and linked to pressure-cooker bombs in Manhattan's Chelsea neighborhood on Saturday. At least 29 people were hurt in the New York City explosion.

Early Monday, one of five similar pipe bombs in a backpack was also accidentally detonated by a bomb squad robot after the explosives were discovered near a pub and the Elizabeth train station, not far from Rahami's home.

As the investigation progressed, the FBI and State Police released photos of Rahami, warning he was considered "armed and dangerous."

Hours after the Elizabeth blast, Linden police responded to reports of a man sleeping in front of Merdie's Tavern, according to the town's mayor, Derek Armstead. Officers "immediately realized it was the suspect," he said.

A uniformed officer approached Rahami outside the East Elizabeth Avenue bar around 10:30 a.m., when the suspected bomber immediately pulled a handgun and shot the officer in the torso, prosecutors said. The bullet struck the officer's protective vest.

More officers arrived and exchanged gunfire with the suspect, according to authorities. Rahami was shot several times outside an auto repair shop several blocks west of the bar.

The prosecutor's office said investigators recovered a handgun from Rahami, who remained held at University Hospital in Newark and was also expected to face federal terrorism-related charges.

Meanwhile, officials identified the wounded officers as Officers Angel Padilla and Peter Hammer.

One officer was shot in the abdomen and another was hit in the head by a bullet fragment, authorities said. None of the injuries were life-threatening.

Noah Cohen may be reached at ncohen@njadvancemedia.com. Follow him on Twitter @noahyc. Find NJ.com on Facebook.