The would-be suicide bomber who detonated an explosive device underground near the bustling Port Authority Bus Terminal is a former New York City cab driver who told investigators that he was inspired by ISIS to carry out the attack for revenge, law enforcement sources said.

Akayed Ullah, 27, who is from Bangladesh and was living in Brooklyn, told authorities he was trying to exact vengeance for decades of violence against Muslims in Gaza, Syria and Iraq, saying in sum and substance from his hospital bed: “They’ve been bombing [my people] and I wanted to do damage here,” sources said.

He told cops he was inspired by ISIS, but police don’t believe he had any direct contact with the group, sources said.

Ullah, who officials say is a former city cab driver whose license has lapsed, set off a “low-tech” homemade pipe bomb strapped to his midsection around 7:20 a.m. inside the subway passageway between West 42nd Street and Eighth Avenue and West 42nd Street and Seventh Avenue.

The incident was captured on transit surveillance footage.

Ullah, who had the explosive device affixed to him with Velcro and zip ties, suffered burns to his hands and abdomen, along with lacerations, and injured three others who were in proximity to him. He was ​quickly taken into custody and ​transported ​to Bellevue Hospital.

Immediately following the explosion, an MTA cleaner could be seen on surveillance ​video holding a dustpan and picking up two items off the ground while the bomber was lying in the empty corridor before the scene was locked down, a source said.

All three victims suffered minor injuries that included ringing in the ears and headaches. Two took themselves to Mount Sinai West and one to Mount Sinai Queens, according to officials.

“Let’s be clear that this was an attempted terrorist attack,” Mayor Bill de Blasio said at a press conference in Times Square alongside Gov. Andrew Cuomo and Police Commissioner James O’Neill.

“As New Yorkers, our lives revolve around the subways. When we hear of an attack in the subways, it’s incredibly unsettling,” de Blasio said, adding, “Thank God the perpetrator did not achieve his ultimate goals. Thank God our first responders were there so quickly to address the situation, to make sure people were safe. Thank God the only injuries as we know at this point were minor.”

Cuomo called the incident “one of our worst nightmares.”

“This is New York,” Cuomo said. “The reality is that we are a target by many who would like to make a statement against democracy, against freedom. We have the Statue of Liberty in our harbor and that makes us an international target.”

The governor added: “We are not going to allow them to disrupt us.”

O’Neill said the device “was intentionally detonated,” though sources say it went off prematurely.