A Utah police officer who was being attacked on Friday was saved by a passerby with a concealed pistol, officials said.

The unidentified police officer confronted the attacker, identified as Paul Douglas Anderson, after spotting feet dangling from a donation bin in Springville, FOX13 Salt Lake City reported on Saturday. Anderson got out of the bin, but refused to remove his hands from his pocket.

The officer ordered Anderson to remove his hands out of his pockets. Anderson eventually took his hands out of his pants’ pockets and began repeatedly punching the officer in the face.

Derek Meyer told FOX13 he was driving by the area when he spotted the police lights and saw Anderson attacking the cop. Meyer turned around and pulled out his pistol.

“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, who has a concealed-carry permit, told FOX13. "Outside of that, if I were to use my gun to protect anyone it would be law enforcement or military personnel."

DRAMATIC DASH CAM VIDEO CAPTURES DEADLY OFFICER-INVOLVED SHOOTING

Meyer aimed the pistol at Anderson and yelled at him to stop attacking the officer. Anderson bolted from the scene as responding officers arrived. The attacker, who was found hiding under a flatbed trailer, was arrested and faces several charges, according to FOX13.

The officer suffered a fractured eye socket and lacerations around his eye.

Cpl. Cory Waters of Springville Police told FOX13 Meyer’s quick action helped save the officer’s life.

“Had he not been in the right place at the right time, who knows what would have happened,” Waters said. “But he definitely stopped the attack from continuing and becoming much worse. He might have even saved either one of their lives. It could have gone really bad, even for the suspect.”

Meyer said he stepped in because it was in his nature. He added

“[I didn’t do it] to get any extra attention or to have people talk about me or anything I did,” he told the news station.

Meyer added that he’s sharing his story because there aren’t enough “good stories from responsible, gun-owning people.”

The officer was released from the hospital and is expected to be ok.