The man attempted to pull a gun out of his pocket when it fired, striking him in his groin, investigators said.