A would-be suicide attacker detonated a pipe bomb strapped to his body in the heart of Manhattan’s busiest subway corridor on Monday, sending thousands of terrified commuters fleeing the smoke-choked passageways, and bringing the heart of Midtown to a standstill as hundreds of police officers converged on Times Square and the surrounding streets.

But the makeshift weapon failed to fully detonate, and the attacker himself was the only one seriously injured in the blast, which unfolded just before 7:20 a.m.

Law enforcement officials said the attacker, identified by the police as Akayed Ullah, 27, chose the location because of its Christmas-themed posters, a motive that recalled strikes in Europe, and he told investigators that he set off his bomb in retaliation for United States airstrikes on ISIS targets in Syria and elsewhere.

It was the third attack in New York City since September 2016, and the second in two months, coming only weeks after eight people were killed in a truck attack along a Hudson River bike path. Like the earlier two, the attack on Monday appears to have been carried out by a so-called “lone-wolf” terrorist.

The explosion on Monday morning echoed through the subway tunnels just off Times Square and filled parts of the Port Authority Bus Terminal with smoke as commuters fled. Even as smoke still filled the chamber, Mr. Ullah was subdued by Port Authority police officers After he was subdued, Mr. Ullah was taken to Bellevue Hospital Center, where he was in serious condition with burns to his hands and abdomen, according to Daniel A. Nigro, the commissioner of the New York Fire Department. Three other people had minor injuries, he said.

An immigrant from Bangladesh, Mr. Ullah came to live in Brooklyn through a visa program available to people who have relatives who are United States citizens.

On Monday afternoon, in his first remarks on the attack, President Trump assailed the current immigration system that allows for extended family members, and not just spouses or minor children, to receive green cards.

“The terrible harm that this flawed system inflicts on America’s security and economy has long been clear,” Mr. Trump said in a statement. “I am determined to improve our immigration system to put our country and our people first.”

The attack occurred in a long pedestrian walkway connecting the Eighth Avenue, Seventh Avenue and Broadway subway lines. Among the commuters traveling beneath Times Square was a man in a hooded sweatshirt. Then came a deafening boom — from him — and then smoke.

Everyone ran.

Mr. Ullah had attached the pipe bomb to himself with a “combination of Velcro and zip ties,” said James P. O’Neill, the commissioner of the New York Police Department. It was crudely composed of a length of pipe stuffed with match heads, its ends stopped up. A broken Christmas tree light was the detonator: When lit, the filament ignited the match heads, the device powered by a nine-volt battery.

The explosion, captured on surveillance video, burned and cut Mr. Ullah, but because it did not detonate properly, it did not produce shrapnel, often the deadliest element of a pipe bomb.

“I think he was prepared to die, and we see him connect the wires on the video,” said a law enforcement official who spoke on the condition of anonymity because the assessment of the suspect’s actions was still preliminary.

As people streamed through the station, Officer Anthony Manfredini of the Port Authority Police Department rushed toward the smoke, said Robert Egbert, a spokesman for the main police union that represents Port Authority officers. A former marine, Officer Manfredini, 28, found the suspect on the ground with “visible wires coming from his jacket into his pants,” Mr. Egbert said.

Three other Port Authority officers followed: Jack Collins, Sean Gallagher and Drew Preston. They arrived just as Mr. Ullah was “reaching for a cellphone,” which the responding officers thought might be used to trigger another device, Mr. Egbert said. They dove and wrestled it from him.

“These officers went into this situation blind, only becoming aware of the danger involved once they confronted the suspect,” Mr. Egbert said.

Police released a photo of Mr. Ullah that appeared to have been taken inside the subway walkway after the blast. In it, he is curled in a fetal position; his exposed stomach is blackened.

Mayor Bill de Blasio found himself for the second time in two months calming the city after a terrorist attack, in this case, on the system that moves millions of people across the city every day.

“Our lives revolve around the subway,” he said at a news conference on Eighth Avenue a few hours after the incident. “The choice of New York is always for a reason, because we are a beacon to the world. And we actually show that a society of many faiths and many backgrounds can work.”

“The terrorists want to undermine that,” the mayor added. “They yearn to attack New York City.”

Investigators, led by the Joint Terrorism Task Force, believe Mr. Ullah acted alone, but they only have just begun to review materials from the searches and other leads.

Christina Bethea was in the underground walkway, headed to her job as a security guard, when the explosion nearly knocked her over, sending a haze of smoke into the corridor packed with commuters. She did not see where it came from, she said. “As soon as we heard ‘boom!’ we began to run,” she said. An hour after the attack, she stood outside the bus terminal, calling her mother and father in North Carolina to tell them she was O.K. “I feel good,” Ms. Bethea said. “I am alive!”

All morning, thwarted travelers spilled into the streets of Times Square, towing suitcases in bewildered silence. They gathered at police cordons stretched across the city’s most trafficked thoroughfares, boulevards vacant at the height of the holiday season, and filmed the red lights of scores of emergency vehicles.

On Monday morning, police searched a six-story apartment building where Mr. Ullah may have lived with his parents on Ocean Parkway, as well as two other residences. At around 11 a.m. officers led a woman in a dark coat from the Ocean Parkway home, a gray hijab covering her hair, into a patrol car, and sped off. The area is home to a few thousand Bangladeshi-born residents, and it represents the heart of their Brooklyn community, with stores and mosques centered around Church Avenue.

Mr. Ullah is a permanent United States resident, according to Tyler Q. Houlton, a spokesman for the Department of Homeland Security, having arrived in 2011.

The method of attack — self-detonation, or the attempt at least — introduces something of a new element to a long history of the city as target, a place that has yet somehow avoided the bomb-wearing attackers that are the hallmark of terrorism in places like Israel and Nigeria.

Since the attacks on the World Trade Center in 2001, there have been about 26 terrorist plots against the city that officials have identified as being thwarted “through intelligence, investigation and interdiction,” John J. Miller, the Police Department’s commissioner of intelligence and counterterrorism, said at a news conference on Monday.

But more recently, the string of foiled plots gave way to closer calls.

In 2009, law enforcement authorities prevented a cell of people with ties to operatives of Al Qaeda from carrying out plans to bomb subway trains. A year later, in May 2010, Faisal Shahzad, a Pakistani immigrant, tried to detonate a truck with explosives in Times Square — but his devices did not go off.

In September 2016, a crude homemade explosive crafted from a pressure cooker packed with shrapnel was left on 27th Street in Chelsea, exploding but killing no one. Before Monday, the last attack was on Halloween, when a man spurred by Islamic State propaganda drove a rental truck down a bicycle path on Manhattan’s West Side, killing eight people and injuring 12 others. The many, Sayfullo Saipov, was arrested and charged by federal prosecutors; he has pleaded not guilty.

While no formal announcement had been made, both federal and local law enforcement officials indicated that Mr. Ullah would be prosecuted in federal court in Manhattan by the office of the acting United States attorney for the Southern District of New York, Joon H. Kim.

But by Monday afternoon, the city was busy forgetting. On 42nd Street, tourists strolled unperturbed, or hurried into the reopened bus depot to catch their rides.

Just hours before, John Frank had stood on that street by the Port Authority exit when he felt tremors through the pavement. “That’s how strong it was,” said Mr. Frank, 54. Shaken, he fled a flew blocks away, and stood for a few long minutes, leaning against a garbage can for support.

“In New York City, we are vulnerable to a lot of things,” Mr. Frank said. “These incidents are happening too frequently.”

(Source: The New York Times)