Authorities say a good Samaritan with a handgun thwarted a savage attack on a police officer in Utah.

The good Samaritan in question is Derek Meyer, who told Salt Lake City Fox-affiliate KSTU-TV that he was driving on Main Street in Springville, which is about 50 miles from Salt Lake City, when he spotted police lights – and a man walloping an officer.

The incident happened about 2 p.m. Friday, police said. An officer on patrol saw a pair of feet dangling out of a bin for Tabitha’s Way, a local food pantry that hosts a clothing recycling program.

The feet belonged to a man police identified as Paul Douglas Anderson, who climbed out of the bin but refused to take his hands out of his pockets.

When Anderson finally took his hands out, he balled them into fists and struck the officer repeatedly, according to police. The attack fractured the officer’s eye socket and left him with a scratch near his eye, police said.

That’s about the time Meyer saw the scuffle.

“I carry a gun to protect me and those around me, but primarily I carry a gun to protect my family first and foremost,” Meyer told KSTU. Police said Meyer had a permit to carry a concealed weapon. “Outside of that, if I were to use my gun to protect anyone it would be law enforcement or military personnel.”

He made a U-turn and got out of his car with his gun. He aimed at the man assaulting the officer and ordered him to stop.

Anderson stopped attacking and sprinted away, police said.

Officers from several nearby agencies were called in to help search for Anderson, and a nearby elementary school was placed on lockdown. After half an hour, officers found the suspect hiding beneath a flatbed trailer.

He was taken to jail and charged with assault on a police officer, resisting arrest, theft, burglary and failure to stop at the command of a police officer. Police have not identified the officer involved, who was treated at a hospital and released.

Good Samaritan situations can be unpredictable and do not always go so well for the people intervening, even when the person trying to render aid is an officer and trained.

In 2016 a Texas man named Isidro Zarate was shot and killed in a Walmart parking lot after he told a man beating his girlfriend “take your hands off her.” The man, whom police identified as Teles Mandan Juarez, reached for a secreted gun and shot Zarate in the neck with it.

A few months later, a teenage EMT-in-training trying to help a woman who had been shot by her boyfriend was shot and seriously injured by the boyfriend after he returned to the scene. “If you help her, I’m going to kill you,” the man said, according to the teenager.

And last June, a black off-duty police officer in St. Louis was shot while coming to the aid of officers who had exchanged gunfire with teenagers in a stolen car. The shooters: his fellow officers, who didn’t recognize he was a policeman.