An unrepentant, homegrown Islamic terrorist was sentenced to multiple life terms behind bars Tuesday for setting off a time bomb that injured 31 people in Manhattan’s Chelsea neighborhood as part of a planned wave of attacks across New York and New Jersey.

Ahmad Khan Rahimi, an Afghan immigrant who became radicalized through online postings by al Qaeda and ISIS, had faced ​at least one mandatory life sentence since a jury convicted him in October on eight counts, including use of a weapon of mass destruction.

Chilling surveillance videos played at Rahimi’s trial showed pedestrians enjoying a temperate Saturday night before they recoiled in shock and ran for their lives when his pressure-cooker bomb blew up outside a home for the blind and disabled around 8 p.m. Sept. 17, 2016.

Authorities said it was a miracle no one was killed by Rahimi’s fiendish blast, which sent a nearby dumpster flying more than 120 feet and sprayed shrapnel that tore into the chests, legs and eyes of innocent passers-by.

Among the spectators who packed the Manhattan federal courtroom for Rahimi’s sentencing was a woman who walked in with a guide dog and sat in a row reserved for victims.

Rahimi, 30, who formerly lived in Elizabeth, New Jersey, was caught bragging about his notoriety over a jailhouse phone during his trial, and he later sent a letter to a crony in Germany claiming that only “Allah will be my Judge.”

Prosecutors said Rahimi even tried radicalizing fellow inmates inside Manhattan’s notorious Metropolitan Correctional Center by “distributing propaganda and publications issued by terrorist organizations.”

Before lowering the boom Tuesday, Manhattan federal Judge Richard Berman said “it now appears, if you put two and two together,” that Rahimi was spreading his hate during Friday afternoon prayer sessions that Berman let him attend during the trial.

Additional reporting by Elizabeth Rosner