Mr. Ullah’s case is also one of several in New York in recent years in which the authorities have said that a so-called lone wolf terrorist, inspired by foreign terrorist organizations, carried out an attack on civilians. It came just weeks after an Uzbek man, Sayfullo Saipov, was charged in a truck attack in October 2017 that killed eight people on a crowded Manhattan bike path.

Image Akayed Ullah Credit... New York Taxi and Limousine Commission

Ms. Donaleski told the jury that Mr. Ullah had reviewed online Islamic State propaganda videos, including one encouraging ISIS supporters who could not travel overseas to “take the fight to where you were, including here in America. The defendant did just that.”

Mr. Ullah has been charged with providing material support to the Islamic State, using a weapon of mass destruction and other counts; if convicted, he could face life in prison.

Ms. Donaleski meticulously described how Mr. Ullah, an electrician, built the bomb in his Brooklyn apartment, using a pipe, wires and screws he had taken from his workplace, a construction site a few blocks from the Port Authority Bus Terminal.

He filled a metal pipe with screws and broken Christmas tree lights and mixed an explosive powder that included ground-up match heads, she said. Then he threaded wires into the pipe and used zip ties and duct tape to attach it to his chest, Ms. Donaleski explained. He slipped a wire from the bomb into a hole in his right pants pocket and connected the wire to a 9-volt battery, she said.

While riding the A train to the Port Authority Bus Terminal, he posted a message on Facebook, which read, “Oh, Trump, you failed to protect your nation,” she told the jury.

In court, Mr. Ullah sat impassively at the defense table, even when prosecutors played a security video that showed the blast and him falling to the ground as commuters ducked and shielded their ears. Mr. Ullah seemed to watch more intently as the jurors passed around the jagged pipe recovered from the scene.