NEW YORK — A Bangladeshi immigrant who in 2017 set off a bomb in a busy subway artery beneath Manhattan's Port Authority bus terminal was sentenced Thursday to life in prison for the attack, which authorities said was inspired by his devotion to the Islamic State terrorist group.

Akayed Ullah, 31, wanted to kill as many Americans as possible, officials said, but would-be victims ­were spared because his explosive device malfunctioned. One person sustained a shrapnel wound to the leg, and two other victims were left with hearing damage. Ullah also was injured in the incident.

On the morning of Dec. 11, 2017, Ullah, who worked as a cabdriver after his arrival in the United States, made his way by subway from his home in Brooklyn to the station at West 42nd Street and Seventh and Eighth avenues. He had a bomb strapped to his chest and a battery in his pants pocket.

“O Trump you fail to protect your nation,” Ullah posted on social media before the attack, which occurred as he walked through a tunnel connecting two sets of train platforms. He was en route to Times Square, authorities have said.

President Donald Trump would later highlight the episode in arguing for stricter immigration policies. Ullah was in the United States on a visa for relatives of people already living legally in the country.

The explosion, at 7:20 a.m., filled the subway tunnel with smoke and caused commuters to flee. Police undertook a search for additional bombs.

“Ullah’s motive was clear and unambiguous: a deeply held ideological hatred for America,” acting U.S. attorney Audrey Strauss said in a statement after Thursday’s sentencing in U.S. District Court in Manhattan.

The Islamic State supporter was found guilty at trial in 2018 of providing material support to a terrorist organization, using a weapon of mass destruction, bombing a public place and related counts. On Thursday, U.S. Circuit Judge Richard Sullivan granted federal prosecutors’ request that Ullah spend the rest of his life in prison.

Lawyers for Ullah asked for leniency at his sentencing, arguing in a memo that he was not personally connected to the Islamic State and that he was in the “grips of a personal crisis” at the time of his crimes.

He faced a mandatory minimum sentence of 35 years in prison.