A would-be suicide bomber set off an explosive device underground inside the passageway between the Port Authority Bus Terminal and the Times Square subway station during the Monday morning rush, officials say.

"I just saw the explosion. Guy just, 'boom!'" MTA station clean Sean Monroe said, describing the moment the device went off. "People around him fell to the floor. As soon as they fell, they got right up and started running."

Officials said no one was killed in the explosion that occurred around 7:20 a.m. and the only seriously wounded person was the bomber himself, 27-year-old Akayed Ullah, a Bangladeshi immigrant and former cab driver who was living in Brooklyn.

Police say the suspect, who is now in custody, was wearing an improvised low-tech explosive device.

"A thorough background investigation of the suspect is being conducted by the joint terrorism task force," Police Commissioner James O'Neill said.

O'Neill added that the attack was captured on transit system video cameras and the department is reviewing the video and interviewing witnesses.

The explosion at 42nd Street and Eighth Avenue triggered a massive police response to both the Port Authority Bus Terminal and Times Square.

The attack sent terrified commuters fleeing through a smoky passageway, and three people suffered headaches and ringing ears from the first bomb blast in the subway in more than two decades.

"This was an attempted terrorist attack," New York City Mayor Bill de Blasio said. "Thank God the perpetrator did not achieve his ultimate goals."

Four victims were transported to Mount Sinai in Manhattan, and one person was treated at Mount Sinai Queens. Hospital officials said they were all in stable condition and released later Monday.

"This is one of my nightmares, right: a terrorist attack in the subway system," Gov. Andrew Cuomo later told NY1.

"The good news is: We were on top of it," he said, and "the reality was not as bad as the fear."

Ullah intentionally set off the device, according to the NYPD. Police officials said he made statements before setting off the device. The FBI said the device as based off a pipe bomb.

Ullah suffered burns and wounds to his body and was taken to Bellevue Hospital, according to authorities.

Four Port Authority police officers are credited with arresting him at gunpoint moments after the blast.

NYPD tactical units moved in to secure the area and make sure there were no other bombs.

De Blasio said the threat to New Yorkers related to the explosion is over.

"It's very important for my fellow New Yorkers to know that there are no additional incidents that we know about and there are no additional activities," the mayor said. "What we know now is that this was one individual who, thank God, was unsuccessful."

The bus terminal, which was closed and evacuated shortly after the explosion, has reopened.

The suspect had looked as Islamic State propaganda online and told investigators he acted alone in retaliation for U.S. military aggression, law enforcement officials said.

Appearing on NY1's "Road to City Hall" on Monday, de Blasio said Ullah's background is still being investigated.

"On this individual, we don't have all the facts. There's no indication of a criminal history. There's no indication of previous radicalization, based on what little we know so far," the mayor said. "It is conceivable, as by the way with any crime is conceivable, that someone could be plotting a crime without having shown any semblance of the kind of act they would commit."

In Washington, President Donald Trump said the explosion highlighted the need to change immigration policies, including the type of family-based visa Ullah obtained to come to the U.S. in 2011. Such visas are "incompatible with national security," the Republican president said in a statement.

"America must fix its lax immigration system, which allows far too many dangerous, inadequately vetted people to access our country," said Trump, who campaigned on cracking down on immigration.

The attack near Times Square came less than two months after eight people died near the World Trade Center in a truck attack authorities said was carried out by an Uzbek immigrant who admired the Islamic State group.

Law enforcement officials said Ullah was inspired by IS but apparently did not have any direct contact with the group. Cuomo said there was no evidence, so far, of other bombs or a larger plot. He said officials were exploring whether Ullah had been on authorities' radar, but there was no indication yet that he was.

A senior law enforcement source told NY1 on Monday night that the suspect appeared to be a loner.

"He folded immediately, which is nothing I've ever seen from a terror suspect," the source said.

The law enforcement source said the suspect was not a member of any specific mosque, and preferred to pray at home.

Cuomo said there was reason to believe the attacker looked at bomb-making instructions online.

Investigators described the bomb as a low-tech explosive device attached to Ullah with "Velcro and plastic ties." It was ignited with a Christmas light, matches and a nine-volt battery. The short pipe was packed with explosive powder but did not work as intended. It was not powerful enough to turn the pipe into deadly shrapnel, the officials said.

Investigators said the suspect was seen on surveillance footage putting the circuits together with his hands and igniting the bomb.

Some of the bomb-making materials may have been bought commercially. The pipe may have been obtained from his job where he worked as an electrician, one official said.

Authorities were searching Ullah's Brooklyn home and a nearby rented space, interviewing witnesses and relatives, reviewing his subway fare card and looking for surveillance footage that might show his movements in the moments before the attack.

Security cameras captured the attacker walking casually through a crowded passageway under 42nd Street between Seventh and Eighth avenues when the bomb went off amid a plume of white smoke, which cleared to show the man sprawled on the ground and commuters scattering.

"All we could hear was the chaos," said Elrana Peralta, a Greyhound customer-service worker who was working at the Port Authority bus terminal near the blast, though she did not hear it. Instead, she heard people yelling, "Get out! Get out! Get out!"

Port Authority police said officers found the man injured on the ground, with wires protruding from his jacket to his pants and the device strapped to his torso under his coat. They said he was reaching for a cellphone and they grabbed his hands.

A photo published by the New York Post showed a bearded man crumpled on the ground with his shirt apparently blown off and black soot covering his bare midriff.

Law enforcement officials said the suspect was speaking with investigators from the hospital bed where he was being treated for burns to his hands and abdomen.

He was "all over the place" on the question of motive, but indicated he wanted to avenge U.S. aggression against the Islamic State, one official said.

The officials spoke to The Associated Press on condition of anonymity because they were not authorized to speak publicly about the blast.

Ullah came to the U.S. on an F-4 visa, available for those with family in the U.S. who are citizens, the Department of Homeland Security said. Trump's administration has called for a "merit-based" immigration system that would limit family-based green cards to spouses and minor children. A White House spokeswoman said Monday that the proposed policy would have kept Ullah out of the U.S.

He had been licensed to drive a livery cab between 2012 and 2015, but the license was allowed to lapse, according to law enforcement officials and New York City's Taxi and Limousine Commission. He had been in two car accidents during his time driving, one law enforcement official said.

Ullah lived with his father, mother, and brother in a Brooklyn neighborhood with a large Bangladeshi community, residents said. The family's red, two-story brick home is just off a shopping strip.

A statement on behalf of the family sent by the New York Chapter of the Council on American-Islamic Relations said they were "deeply saddened" by the attack but also "outraged by the way we have been targeted by law enforcement, including a teenage relative of the suspect who was pulled from class and questioned in his school without a parent guardian or attorney."

Authorities said Ullah took the subway from his Brooklyn home and got off at the A train stop at 42nd Street and 8th Avenue. Apparently, he was wearing the bomb the whole time.

Authorities said he was looking to cause death and destruction, and might have succeeded, but the bomb did not fully explode.

"The choice of New York is always for a reason, because we are a beacon to the world and we actually show that a society of many faiths and many backgrounds can work," de Blasio said.

At this time, authorities said Ullah acted alone, but they are questioning his family and friends to gain more insight into his actions. 

Although the FBI and NYPD hunt for terrorists every day, officials say the reality is that they cannot stop every attack.

"This is fact of life whether you are in New York, London, or Paris, the question is, Can it happen here?" said John Miller, the NYPD's Deputy Commissioner of Intelligence and Counterterrorism. "The answer is, It can happen anywhere."

News of Ullah's arrest stunned Alan Butrico, who owns the house next door and a locksmith business two doors down.

"It's very weird," Butrico said. "You never know who your neighbors are."

The last bomb to go off in the subway system was believed to be in December 1994, when an explosive made from mayonnaise jars and batteries wounded 48 people in a car in Lower Manhattan.

The Times Square subway station is the city's busiest, with 64 million riders passing through every year. The subway system as a whole carried over 1.7 billion people last year.

Monday's explosion triggered a massive emergency response both above and below ground, halting what would ordinarily be a bustling rush hour at the "Crossroads of the World." But streets quickly began returning to normal.

Security was beefed up at Madison Square Garden and Barclays Center in response to the subway attack.

The Rangers and Islanders played home games Monday night.

Spokespeople for their arenas released statements saying the safety and security of their guests is the most important thing. The teams said they are working closely with law enforcement.

The Knicks and Nets have home games Tuesday.

City Councilman Ydanis Rodriguez accused Uber and Lyft of enacting surge pricing in the city after the bombing.

"As chaos was unfolding, Uber and Lyft made the decision to enter surge pricing. Shortly after, they backtracked and began to issue refunds to the passengers who received the inflated prices. It is shameful, that these companies made the decision to put profit over the safety of New Yorkers who saw them as an alternative means to arrive to work safely. I am calling on these companies to make a commitment to stop price gauging New Yorkers in times of disaster, severe inclement weather or any other unforeseen circumstances. If they want to be in New York and thrive in here they cannot continue to operate as business as usual when our city is suffering through a tragedy," Rodriguez said in a statement.

In response, Uber said," Within minutes of seeing reports of an incident, we disabled dynamic pricing in the area. In addition, we are proactively refunding riders for dynamic pricing on affected."

___

Associated Press writers Tom Hays, Jennifer Peltz, Jake Pearson, Kiley Armstrong, Larry Neumeister and David James Jeans in New York, Michael Balsamo in Los Angeles, Matt Pennington in Washington, D.C., and AP researcher Rhonda Shafner in New York contributed to this report.