The man who came upon the scene warned the suspect to stop striking the officer, but the assailant continued, said Capt. Damon Cecil, a spokesman for the Arizona Department of Public Safety.
The good Samaritan got a gun from his car and shot the suspect, who died at the scene.
The trooper, a 27-year veteran, was shot in the chest and shoulder. He is in serious and stable condition, Cecil said.
The trooper was identified Friday as Ed Andersson.
Col. Frank Milstead, director of the Public Safety Department, said he would like to thank the man who stepped in. "I don't know that my trooper would be alive today without his assistance," he said, according to CNN affiliate KNXV-TV
Public safety spokesman Bart Graves said the incident began with the trooper responding to report of shots fired from the median of an unlit, rural section of Interstate 10 near Tonopah. Andersson came across a vehicle that had rolled over and got out to investigate. While Andersson was setting flares, the suspect shot him.
It was not clear where the suspect was when the officer pulled up.
Milstead said at some point the suspect started beating Andersson, who was unable to use his right arm to defend himself. That's when the motorist pulled up and opened fire on the suspect.
"It's fairly rare" that citizens who come to the aid of law enforcement officers use deadly force, Cecil said.
Another motorist who stopped used the trooper's portable radio to call in the shooting.
The conversation between that driver and the dispatcher was very businesslike, Cecil said.
"Hello. Officer down, officer down outside Tonopah. Come in, please," the man says, according to audio archived on Broadcastify, which streams radio communications between emergency responders. "He's in real bad shape. Please send air support, helicopter, please."
He tells the dispatcher there are two other people who are down in an "unknown condition."
Cecil praised the motorists who stopped to help, saying, "They were calm, determined."
A woman who was ejected from the vehicle died at a hospital, authorities said.
Authorities didn't release the names of the people involved in the incident, which occurred after 4 a.m. near mile marker 89, west of Tonopah. That city is about 50 miles west of Phoenix.