To safely muzzle a dog, first get the shoelace (or equivalent piece of cord, rope, leash, whatever) and tie a loose knot in it, with the loop left open. Slip the loop over the dog's muzzle, as in the first picture, then tighten the knot so that the dog's mouth is closed. you don't have to make it tight enough to hurt, just close the mouth so you cannot be bitten.
Once caution in this step - until the loop is secured over the muzzle, the dog can bite. Be careful. If it is not your dog, be particularly careful. You might want to wait until the owner arrives, or you can get help. If you decide to go ahead and help the dog, use utmost caution and make sure that other people are also out of danger.
After the knot is snugged down, pass the ends of the shoelace under the chin and cross underneath. This adds a second loop to the muzzle and will help it to stay on.
Lastly, tie the shoelace ends behind the dog's head to secure.