An armed man drove his car into Temple Israel, a synagogue outside Detroit, during an attack this week, and the attacker died after being shot by a private security guard inside the building, the FBI said.

FBI Special Agent in Charge Jennifer Runyan of the Detroit field office said the gunman, Ayman Mohammad Ghazali, eventually fatally shot himself with his own weapon after the private guard fired back. The car’s engine caught fire during the attack.

Runyan said the incident began with gunfire through the windshield in a hallway inside the synagogue. When the car barreled in, there were 140 students inside an early childhood learning center, and all were unscathed.

Sen. Elissa Slotkin credited the synagogue’s security preparations and said, “If they had not done their job almost perfectly we would be talking about an immense tragedy here today with children gone,” according to Slotkin. Michigan Gov. Gretchen Whitmer added that “These heroes threw themselves in harm’s way, engaging a suspect.”

A Temple Israel rabbi said “it was only a miracle” that none of its members were hurt, according to the account. Rabbi Jennifer Kaluzny, speaking to CNN, said, “Unfortunately the entire Jewish community, no matter where we are in the world, we have to plan for things like this,”

The security buildup at Temple Israel began months before the attack, following what officials described as rising antisemitism and other attacks at places of worship. The synagogue hired Danny Phillips, a former police lieutenant, as its head of security for its in-house armed security guards, with the temple describing the hire as proactive and “in response to the evolving realities facing Jewish communities.”

Phillips served in law enforcement for almost three decades, including more than 20 years as an advanced firearm instructor, according to information cited from a college website where he teaches a police academy course on responding to active assailants. The synagogue also held active shooter training, and its social media accounts said that in January its staff and clergy participated in active shooter prevention and preparedness training led by an FBI official.

Oakland County Sheriff Mike Bouchard said he contacted the temple’s head of security two days before the attack and credited “thorough preparation” ahead of the attack for why there weren’t casualties.

The episode prompted broader attention to church and synagogue preparedness efforts in Michigan as well. Ron Amann, a member of a safety team at CrossPointe Community Church in Wayne, said he was still recovering after being shot in the leg last June when a man tried to attack the Christian church and was killed before he could enter a Sunday service. Amann said he passed his grandson to his wife when he heard a woman yell, “There’s a man with a gun.” He added, “When you sign up for the safety team you have to be willing to stand up and fight, bluntly, rather than run the other direction,” and said, “My alertness is just at a higher level than it ever was before.”

CrossPointe Community Church, about 30 miles (48.2 kilometers) from the synagogue, sheltered in place after hearing about the attack, Pastor Bobby Kelly said. Kelly said, “When you hear of something happening,” “you don’t know where it’s going to happen next.”

The security steps at Temple Israel came as houses of worship across the country have increased protections, with the AP account linking some of the heightened concern to the broader context of the U.S. and Israel launching a war with Iran.