How many times have you said something only to regret it later? Why did that last conversation go so badly? How did we end up shouting at each other? The answer is our negative emotions. Those pesky things that generate adrenaline in case we have to fight or flee.
The next time that you can feel your negative emotions welling up inside, hold back on saying the first thing that comes into your head. Take a long, deep, slow (silent) breath to give your brain the chance to engage before your mouth starts operating. This will allow blood to flow into your brain, will slow the conversation down, will place a lid on your negative emotions, and will allow you the time to reflect on what you are about to say.
If you have said something that you later regret and are feeling bad about it, be the first to say sorry. Don't us the word 'apologise' because that is insincere. Say you are sorry and mean it. You will feel much better and have probably made a good friend from the negative encounter.