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.