I read your post and I think that you already are aware of what is causing this. It sounds like you are experiencing performance anxiety
which is anxiety relating to your sexual performance. This is very common in men. This anxiety and worry obviously interferes with your sexual behavior and leads to you losing your erection. This understandably is causing you disappointment and I wouldn't be surprised if you told me that you now may be also avoiding having sex altogether to avoid the disappointment and embarrassment. Before you realize it, your own thinking "I won't have an erection and I will disappoint my girlfriend" causes you anxiety and this has a physical effect on your body which makes you lose your erection. This creates another vicious cycle of thinking that you possibly have a problem and perhaps that your girlfriend is dissatisfied with you and that creates more anxiety next time you attempt to have sex and of course you lose your erection again. This slowly creates a pattern and you start believing that this will be the case every time. However, what may have happened at the beginning could have been the case of yo having drunk a lot, or perhaps being very tired or even very excited or anxious that interfered with your erection the first time. And then you allowed yourself to think negatively about this happening again which created the vicious cycles I mentioned before. Think about the circumstances that this happened the first time. Don't forget that losing an erection can happen due to many reasons.
Therefore, it is very likely that you are allowing yourself to enter these vicious cycles by thinking negatively, you may be causing this to yourself.
Some suggestions would be to talk to your girlfriend about how you feel. Also, when you are intimate with her do not attempt to have sex, just enjoy being intimate without attempting to have sex. Do not relate sex with performance as this causes you more anxiety. Enjoy being intimate and allow yourself to feel the pleasure without making any goals or plans.
You need to understand that you are causing this by your negative thinking so this thinking needs to be challenged by you. You have no evidence to suggest that this is a physical problem so I would say that this is a product of your anxiety that you are unnecessarily causing to yourself.
Understand what is stressing you and talk about it with your girlfriend. Allow her to show you that you have no reason to stress
yourself and try to challenge your negative thinking.
I hope that helps. Please let me know if you have any comments in this.