An armed passerby likely saved an Arizona state trooper’s life Thursday, officials said, after an attacker opened fire as he responded to an emergency call.

Trooper Edward Andersson was at a traffic stop early Thursday morning when he was notified that a hidden assailant was shooting at cars on a rural section of Interstate 10 near Tonopah, an area about 50 miles west of Phoenix.

When Mr. Andersson approached the scene, he found an overturned car with a woman ejected from the vehicle. As he began setting up emergency flares around the accident, the suspect began shooting at the trooper in what authorities are calling an ambush-style attack, hitting the officer in the shoulder and chest. The suspect then began beating up the officer when another motorist pulled off the highway to see if the trooper needed help.

After asking Andersson if he needed assistance and warning the suspect to stop harming the officer, the motorist fatally shot the attacker and then used Andersson’s radio to call for help.

“I would just say, at this point, ‘Thank You,’ because I don’t know that my trooper would be alive today without his assistance,” Col. Frank Milstead told reporters Thursday.

Gun rights advocates have argued that scenarios like this are a reason to expand gun rights.

“An armadillo: he has a defense system. Every animal does. Humans can use our brains. And we can use guns as a defense, not an offensive. It’s the ultimate defense – it levels the playing field,” National Rifle Association World Shooting Champion Dianna Muller told The Christian Science Monitor in September. “Good guys with guns do make a difference.”

Although Texas made news in late 2015 for its new open carry law, Arizona has been ranked consistently among the best states for gun owners in the United States.

“Arizona gets full points in every category with both permitless and permitted carry, strong self-defense laws, a ‘shall sign’ [National Firearms Act] statue and a thriving competitive shooting scene,” writes the advocacy website Guns and Ammo. Additionally, Arizona has a “defense of third person” law which permits a citizen to use deadly force with a weapon if they see someone threatening another person – as was the case on Interstate 10 Thursday morning.

The woman ejected from the vehicle, as well as Andersson’s attacker, did not survive the attack. The trooper is at a hospital in Arizona in stable condition.

“This incident is another reminder of the risks that the men and women who wake up each morning and put on the badge take for our state,” said Republican Gov. Doug Ducey in a statement Thursday. “I urge Arizonans to join me in praying for a quick recovery for this brave officer and thanking everyone who, through their actions in real time, showed our officers exactly what Arizona means when we say: ‘You have our backs – and we will always have yours.’ ”

This report contains material from the Associated Press.