Very well said, Julia! Sometimes we have a strong emotional reaction that has little to do with the situation. As you said, maybe we are tired, frustrated, "pre-programmed", or a variety of other things and that fuels our response rather than the specific interaction.
Mistakes happen and we say or do things we regret. Offering and accepting an apology is an important first step. I'm glad your friend gave you space and then came back and talked to you. He sounds like a good friend. : )