A 28-year-old man hunted in connection with bomb blasts in Manhattan and New Jersey was caught Monday after shooting two cops in New Jersey, where he had been found snoozing in a bar vestibule, authorities said.

Afghani native Ahmad Khan Rahami of Elizabeth was injured in the Linden shootout after he struck one cop in his vest and injured another officer when his bullet smashed a police car’s window, grazing him in the face, officials said.

“We have every reason to believe this was an act of terror,” Mayor Bill de Blasio said during an afternoon press conference in which he urged New Yorkers to submit tips by calling 800-577-TIPS.

Rahami — whose fingerprint was found on an unexploded device — was wanted in connection with the explosion in Chelsea that left 29 wounded Saturday night and other incidents in the two states that sparked fears of a local terror cell, according to federal officials.

But FBI Assistant Director William Sweeney said during the press conference that “there’s no indication there is a cell operating here.”

Rahami, a US citizen, is believed to have acted alone and authorities were not searching for additional suspects, officials said.

Sweeney said five men were held by the FBI after agents stopped their car in Brooklyn as they headed over the Verrazano Bridge from Staten Island.

The vehicle was stopped in connection with Rahami and the occupants were questioned — but not arrested, Sweeney said.

After the traffic stop, authorities searched locations in Elizabeth and Perth Amboy in New Jersey before sending a cellphone alert about Rahami that de Blasio said was “very helpful” in tracking him down.

“Even though we have a suspect, we will have a very strong and visible NYPD presence throughout the week,” Hizzoner said.

US Attorney Preet Bharara said he and his New Jersey counterpart will be working together to bring charges against Rahami in a “careful and thorough” manner.

Linden Mayor Derek Armstead said Rahami was tracked down after a bar owner reported someone asleep in his doorway about 10:30 a.m.

“About 10:30 we received a call about a gentleman sleeping in the doorway of a local business. The business was closed at the time. Four officers responded,” Linden police Capt. James Sarnicki said.

“When an officer went to rouse the man that was sitting down, the man picked up his head and the officer saw that he had a beard and resembled the person on the wanted poster. The officer then told him to show your hands and the suspect pulled out a handgun and fired a round at the officer, striking him in the abdomen,” he said.

“The officer had his bulletproof vest on so he didn’t sustain a serious injury. A second police car arrived on the scene, and I understand the suspect shot at that car and the bullet went through the windshield and glanced off the officer’s forehead, causing an injury — fortunately also not serious,” he added.

The suspect then engaged cops in a “walking gun battle,” firing his weapon “indiscriminately,” he said.

“Eventually additional officers responded and returned fire and were able to take him down,” he said.

A surveillance image released by New Jersey State Police of a man believed to be Ahmad Khan Rahami.NJ State Police

Two witnesses described coming across Rahami, who they thought was a slumbering homeless bum before all hell broke loose.

Jack Mazza, 55, a mechanic who works nearby, said he and a pal, Harry, were walking past Merdie’s Tavern – which belongs to Harry — when they saw a man in a hoodie snoozing in a vestibule.

“Harry said, ‘That’s the guy! That’s the guy that planted the bomb.’ I said, ‘No it’s not, you can’t even see his face. How do you know?’ Because he had a hoodie on. I bent down and looked at him and said, ‘I don’t know. Call the cops if you think it’s him,’” Mazza said.

When Harry told the man to split, he shot back “Go f–k yourself! I’m sleeping!”

Harry then noticed the bearded man’s appearance and called police.

“A few minutes later the cops showed up and the guy pulled out a gun and started shooting through the glass at them,” Mazza said. “The cops were chasing him and he was shooting while he was running. I guess he was trying to shoot the cops but he was hitting passing cars. It’s a miracle nobody got hurt. He could have hit us. He could have hit anyone.”

It’s a miracle nobody got hurt. He could have hit us. He could have hit anyone.”

- Jack Mazza, witness

Acting Union County Prosecutor Grace H. Park said Rahami was shot in the leg and was undergoing surgery, NJ.com reported.

Earlier Monday, FBI agents and members of the Bureau of Alcohol, Tobacco, Firearms and Explosives stormed an apartment where Rahami lives above the family’s restaurant — First American Fried Chicken — on Elmora Avenue.

The raid came after one of five devices found in a backpack at the nearby train station exploded while a bomb squad robot tried to disarm it. No one was injured.

Authorities have evidence that Rahami also was connected to an unexploded device on West 27th Street and a blast Saturday morning at Seaside Heights, New Jersey, ahead of a race for Marines and sailors, a source told The Post.

Authorities also were able to identify the suspect with the help of a cell phone left behind with a pressure cooker found on 27th Street — blocks away from the explosion on West 23rd Street, a source told ABC News.

A law enforcement official told the New York Times there was no direct evidence yet linking Rahami to ISIS or al Qaeda.

“We don’t know his particular ideology or what his inspiration was or whether he was directed or whether he was inspired,” the official said. “We don’t have any of that.

Emergency personnel work at the scene of Saturday’s explosion in Chelsea.AP

“So, the ideology, the connection to international terrorism, we might flesh that out as we go through the results of search warrants, looking for computers, discs, things like this. Search warrants that we did Sunday night at the residence in Elizabeth,” the official added.

“Here’s a guy who has been involved in what appears to be four bombings in rapid succession in recent days in crowded places,” the official said. “So we need to get him.”

Elizabeth Mayor Chris Bollwage said at a press conference that Rahami’s father, Muhammad, opened the 24-hour-a-day eatery about 10 years ago and employed his sons.

Neighbors complained about the restaurant, which attracted noisy crowds of customers — some of whom urinated on people’s properties.

see also

The city council voted to shut it down by 10 p.m., but neighbors said the Rahamis ignored the directive and sued the mayor, the city and about 20 cops — claiming ethnic and racial discrimination.

Gov. Andrew Cuomo said it was too early to say if Rahami has ties to international terrorism.

“I said yesterday I believe it was an act or terrorism,” he said at a press conference at Penn Station on Monday. “By definition, terrorism (is) taking an action on human lives.”

He said no group has taken responsibility for the incidents and that there was “no hint of foreign terrorism.”

Earlier in the day, he said there may be a foreign link to the explosion Saturday night in Chelsea.

“I suspect there may be a foreign connection,” Cuomo told CBS News. “That’s what we are hearing today, as the investigation goes on.”

President Obama, who is in the Big Apple for the annual UN General Assembly gathering, praised federal and local law enforcement authorities for their efforts — stressing that the US will continue to lead the way in the fight against ISIS.

The president also said investigators see no connection to the stabbings in Minnesota.

Ryan McCann, 33, said Rahami has been working behind the counter at his father’s eatery for about five years.

“He’s a very friendly guy, very Americanized. You would never expect anything like this. It’s terrifying because he’s been hiding in plain sight,” McCann told The Post.

Speaking at a press conference, Elizabeth’s mayor said “you have to wonder how many people could have been hurt.”

Elizabeth NJ. Mayor J. Christian Bollwage speaks to press.AP

“I’m extremely concerned for the residents of the community, but more importantly extremely concerned for everyone in the state and country where someone can just go and drop a backpack into a garbage can that has multiple explosives in it,” Bollwage said.

The unexploded pressure cooker, which was found on West 27th Street and defused safely after the blast on West 23rd Street, was sent to the FBI in Virginia for forensic examination.

The Chelsea bomb contained a residue of Tannerite, an explosive often used for target practice that can be picked up in many sporting goods stores, a federal official said Sunday.

Cellphones were discovered at the site of the bombings, but no Tannerite residue was identified in the New Jersey bomb remnants, in which a black powder was detected, said the official, who wasn’t authorized to comment on an ongoing investigation and spoke to the Associated Press on condition of anonymity.

Also on Sunday, FBI agents searched an Uber driver’s vehicle that had been badly damaged in the Chelsea blast after the driver picked up three passengers.