A pair of well-dressed thieves, two homeless men, a bar owner – and some incredible luck – combined to limit the casualties in weekend terror attacks in New Jersey and New York, and the bungling bomber himself also made numerous mistakes that helped foil his plans.

The carnage caused by a series of pipe and pressure cooker bombs injured just 29 people, none critically. No one died – a particularly amazing stat considering the intended targets included runners competing in a charity race, people walking down busy New York City sidewalks and residents gathered at a New Jersey train station.

But in every instance, either through folly or happenstance, the alleged terrorist, Ahmad Khan Rahami, was thwarted.

Rahami is alleged to have started his weekend of terror on Saturday morning in New Jersey’s Seaside Park by planting several pipe bombs, strung together, in a trash can along the route of a charity 5K. One of the bombs exploded at 9:30 a.m., precisely when a group of runners would have likely been in the vicinity.

Except, when the blast occurred, no one was near the trash can.

That’s because the start of the race, set for 9 a.m., was delayed when officials discovered an unattended backpack – which had no connection to Rahami. Further, only one of the pipe bombs detonated. The rest failed to explode and were eventually rendered safe by a bomb squad technician.

Later that night, Rahami is accused of dragging two duffel bags, each loaded with a pressure cooker bomb, to locations on W. 27th St. and W. 23rd St. in New York City. Here, he made several mistakes. He placed the bomb on W. 27th St. either next to or underneath a Dumpster, so that when the bomb exploded, the blast force was partially dampened by the heavy metal bin. The explosion injured 29 people, but was the only one of Rahami’s attacks that wounded anyone.

Rahami’s device on W. 27th St. never went off. Because of that, authorities were able to inspect the bomb, reportedly lifting at least one of Rahami’s fingerprints. His flip phone, the likely detonation device, was also attached to the pressure cooker.

Officials found the unexploded W. 27th St. bomb in a plastic trash bag. That’s because two “well-dressed” men happened upon the bomb-bearing duffel bag, dumped the odd-looking device in a garbage bag and made off with the luggage, officials said during a Monday news conference. It’s unknown if the bomb failed to explode due to a design flaw, or if the thieves unintentionally disabled it when they threw it in the trash.

The next night, two homeless men found a backpack in a trash can at the Elizabeth, N.J., train station around 8:30 p.m. Thinking there might be money or other valuables inside, they took the bag and opened it up. When they saw wires, however, they called the cops. One of the pipe bombs inside detonated when it was handled by a bomb squad robot, though the rest failed to explode.

By Monday morning, Rahami was named as the prime person of interest in the bombings. At 8 a.m. a mass text alert went out to people near New York City urging everyone to be on the lookout for Rahami.

But any fears of a drawn-out manhunt were short-lived. The 28-year-old was found sleeping in the doorway of a bar by the building’s owner shortly after 10 a.m. That man called police officers, who recognized Rahami.

The alleged terrorist engaged in a brief gun battle with police, and two officers suffered minor injuries. But Rahami was quickly brought down and taken into custody.