LINDEN, N.J. — Ahmad Khan Rahami, wanted for questioning in connection to explosions in Chelsea and New Jersey, is in custody following a shootout with police officers, a top law enforcement official said.

Rahami, 28, was found sleeping in the hallway of a Linden, N.J., bar by the business' owner. The sleeping man was initially presumed to be a vagrant, but police officers who responded quickly realized it was the man FBI officials warned was "armed and dangerous."

The officers ordered the man to show them his hands and he allegedly pulled out a gun and opened fire, said Capt. James Sarnicki, with the Linden Police Department.

A bullet struck an officer in the vest and another went through the windshield of a police cruiser, grazing a second officer, who was called to the scene as back-up, in the forehead, Sarnicki said. Neither officers' wounds are considered life-threatening.

Rahami was struck multiple times and detained following the shootout, the local mayor said shortly after 11 a.m. The NYPD later confirmed his arrest.

In addition to the two injured officers and Rahami, a third, unidentified person was hurt, authorities said.

In a tweet, Union County officials said two people, described as primary and second suspects, were detained. But the officials later posted a "corrected" tweet saying the man captured is "the suspect involved in recent bombing attempts in our area."

Images from the scene showed Rahami on the ground and apparently injured. He was loaded on a stretcher into an ambulance. Video from the scene showed his right arm bloodied but the suspect was alert and conscious when he was taken away.

Rahami was initially identified Monday morning as a person wanted for questioning in connection to a bombing in Chelsea on Saturday that resulted in 29 people being injured.

Within hours, agencies said the Chelsea explosion was likely linked to two others in New Jersey's Seaside Park and Elizabeth communities, and CNN reported Rahami was also wanted in connection to those blasts. Rahami was identified Sunday through a fingerprint, CNN reports.

A cellphone on a pressure cooker found at a fourth scene on 27th Street provided additional clues, according to the news network. The makeshift explosive was spotted after the Chelsea explosion the night before and safely removed.

"We have every reason to believe this was an act of terror," NYC Mayor Bill de Blasio said at an early afternoon news conference Monday.

Prior to his capture, the New Jersey man was considered "armed and dangerous," according to the FBI.

President Obama said it was remarkable Rahami was already in custody, a White House statement said. Obama called it a "feat of law enforcement competence."

Rahami is of Afghan decent and his last known address is in Elizabeth, New Jersey, according to the FBI.

The Associated Press reports Rahami lived with his family above a restaurant owned by his father, a few miles from Newark Liberty International Airport.

Following the announcement of Rahami's capture, applause broke out at the Malibu Diner in Chelsea, which is located near the scene of Saturday night's bombing.

That response was quickly echoed by officials.

"You can hear a collective sigh of relief from all New Yorkers and deep appreciation to the men and women who protect us each and every day," said U.S. Rep. Carolyn Maloney (D-Manhattan).

As the news of Rahami's arrest broke, President Barack Obama spoke of the attacks and praised the response from citizens in New York and New Jersey.

"Folks around here, you know, they don't get scared. They are tough, they are resilient, they go about their business every single day. And that kind of toughness and resoluteness and a recognition that neither individuals nor organizations like ISIL can ultimately undermine our way of life. That's the kind of strength that makes me so proud to be an American," Obama said.

The motive for the attacks is still being investigated, and the Chelsea bombing may have been an act of terrorism with a foreign connection, New York Gov. Andrew Cuomo said Monday.

“Today’s information suggests it may be foreign related, but we’ll see where it goes,” Cuomo told the Associated Press.

Terror attacks are increasingly global, but New York is a target and authorities and locals should always be in a state of readiness, Cuomo told reporters Monday at Penn Station, where he met with first responders.

“Be vigilant. Be on constant guard. Just assume there could be a terrorist attack anytime, anywhere,” Cuomo said.

With the United Nations General Assembly meeting this week and Obama in town, there's already an increased NYPD presence across the city, de Blasio said Monday. But with the explosion, there will be a "very strong and visible" contingency of officers checking bags and patrolling subways, the mayor said.

"We want that high level of readiness from the NYPD," de Blasio said.

In addition, the explosions have lead authorities to signs of a possible terror cells in New York and New Jersey, law enforcement officials told CNN.

A raid was conducted early Monday morning at an apartment in Elizabeth — the area in which Rahami was last known to live. Officials would not confirm if the raid was connected to him.

PIX11's Paige Leskin contributed to this report.