Your job is to remain as calm as possible. Leaving the situation helps everybody, even if it means you'll have to go back to the store later to finish your shopping. If you can't leave altogether, try to leave the immediate scene. For example, if you're in the dentist's waiting room, try at least going out into the hall or parking lot. Once the tantrum subsides, your child may need hugs and reassurance.
Children can get scared by being that out of control.
Hugs are fine, but don't change the rules after a tantrum. If you told your child that it was time to leave the playground and he responded with a tantrum, it's still time to go when the tantrum is over. But once you know how strongly he feels, you can acknowledge those feelings and try to make leaving less painful by offering to read a favorite story when you get home. Keep in mind that your child's tantrum is nobody's business but yours. Your toddler will have tantrums, and some of them are bound to happen in public.