An ISIS-inspired would-be suicide bomber detonated a homemade pipe bomb strapped to his chest in a pedestrian tunnel packed with commuters beneath the Port Authority Bus Terminal in Manhattan, during Monday’s busy morning rush, authorities said.

Police quickly apprehended suspected terrorist Akayed Ullah, 27, of Brooklyn, who suffered non-life-threatening injuries along with three others, moments after the attack at one of the nation’s busiest transportation hubs. It happened just five weeks after another ISIS-inspired terror attack on Halloween on Manhattan’s West Side that left eight people dead and a dozen injured.

Ullah, a native of Bangladesh who has been in the United States for seven years, is believed to have acted alone and told investigators that he tried to carry out the bombing in support of the Islamic State terror group. He said he was motivated, in part, by al-Qaida’s online propaganda magazine Inspire, according to law enforcement sources with knowledge of the investigation.

Ullah, said a high-ranking law enforcement source, voiced anger during interviews with investigators about the historic treatment of Muslims.

“This was an attempted terrorist attack,” Mayor Bill de Blasio said at a news conference. “Thank God the terrorist did not accomplish his goal.”

The New York Times on Monday, citing several law enforcement sources, reported that Ullah carried out the attack in retaliation for American airstrikes on ISIS targets in Syria and other places. The Times, again citing sources, also reported that Ullah picked the bus terminal because of its Christmas-themed posters, which he told investigators recalled attacks in Europe against Christmas markets.

President Donald Trump, in a written statement, denounced what he called the country’s “lax immigration system, which allows far too many dangerous, inadequately vetted people to access our country.”

The president added: “Today’s terror suspect entered our country through extended-family chain migration, which is incompatible with national security.”

The Department of Homeland Security has confirmed that the attacker was admitted to the country after presenting a passport displaying an F43 family immigrant visa in 2011, White House Press Secretary Sarah Huckabee Sanders told reporters Monday. That classification means Ullah was the child of someone who is the sibling of a U.S. citizen.

Ullah had strapped the crudely fashioned device to his body with a combination of Velcro and zip ties, police said. It consisted of a pipe measuring about a foot long and filled with shrapnel and powder and was detonated by a Christmas ornamental light, a source said. Ullah told police he assembled it in Brooklyn, the source said.

The pipe itself fractured but did not explode as fully as the suspect had intended, the source said.

The source said the explosion, if it had detonated properly, “could have inflicted a lot more harm.”

Ullah was taken to NYC Health and Hospitals/Bellevue with burns to his abdomen and hands, the FDNY said. No charges had been filed as of Monday night.

Three others also suffered non-life-threatening injuries, according to the FDNY. All three took themselves to hospitals, suffering from headaches and ear-ringing.

The bus terminal, which serves as a hub for several subway lines and bus services operated by companies such as Greyhound, was evacuated following the 7:20 a.m. explosion, which occurred in a passageway connecting Times Square to Eighth Avenue, officials said.

The terminal re-opened just hours after the attack and while several subway lines were re-routed and suspended for hours, they were back up and running for the evening commute.

As National Guardsmen and NYPD flooded the area, Gov. Andrew M. Cuomo said from the scene that the attack would not interrupt New York’s normal course of business. “We’re not going to allow them to disrupt us — that is exactly what they want and exactly what they’re not going to get,” he said.

One of those in the pedestrian tunnel when the bomb went off was John Lara, 51, a handyman from the Bronx. He said he was walking to the subway when a “stampede” of people came toward him.

“ “I saw a lady get knocked to the ground,” he said. “I just kept running.”

An NYPD official said the attack will likely result in tighter security for Times Square’s New Year’s Eve ball drop, including police using enhanced magnetometer screening and canines that can detect mobile explosives up to 10 minutes after a person has left an area.

Rep. Peter King (R-Seaford), who was briefed by the FBI, agreed it appeared Ullah acted alone and had no “red flags,” meaning no criminal record or terror affiliations. Investigators are interviewing Ullah’s family and going through his social media accounts, phone records and messages, as well as financial records looking for large deposits or withdrawals, King said.

Police, some carrying rifles, descended on Ullah’s home on East 48th Street in the Flatlands section of Brooklyn, blocking off the street to traffic Monday.

Shawnda Brown, 39, who lives a few houses from suspect said it was scary to know that the bomb was assembled yards from her home.

“The proximity is startling,” Brown said. “Jesus, literally, he had a bomb. He had to get to the Port Authority, so he’s like riding around with the bomb.”

Ullah held a Taxi & Limousine Commission For-Hire Vehicle Driver’s License, which would have allowed him to drive a black car, community livery or limousine, from March 2012 through March 2015, at which time it lapsed and was not renewed, said TLC spokeswoman Rebecca Harshbarger.

On Long Island, Nassau and Suffolk police said they have received no specific threats, but they are monitoring the situation and will increase patrols in certain areas as a deterrent.

Officials from both departments said they will have more of a presence at transportation facilities, including Long Island Rail Road stations. In Nassau, police said they will give increased attention to places where large groups of people might gather, including shopping malls, theaters and concert venues.