It sounds like an impulse control problem and this might be overkill as an answer, however -
If you are serious about changing your behaviour then it could take some time and effort. I'd start with keeping a diary of your emotional state within social situations and recognising which emotional states and which social situations are more likely to create the behaviour that you don't want.
What you are looking for are early triggers. Things that will mark this type of behaviour within you in advance giving you an opportunity to change your patterns.
Then you can start with dealing with the problem - if you recognise that it is an emotional reaction or reaction to stress then you can look at stress handling methods, emotional regulation methods in order to take control over your choices and actions.
Or perhaps it requires a more mechanical method like ensuring you count to 3 in these situations before saying anything. But once you know your triggers it is easier to put yourself in this mode where you question what you say without having to be in that state at all times. You learn to catch it early.
I am definitely not a therapist, and if it is an impulse control that is effecting your relationships or creating undue stress on you then it may be worth talking to a Cognitive Behavioural Therapy (CBT) practitioner. It has handy methods around impulse control and choices