Despite your heart pounding and moving up into your throat, your mind has to ignore your body's pleas and continue sending signals to keep working at that same level of effort. Your mind is the key component to this and critical to any success you'll achieve.
It's all About Mental Toughness
You can follow a training plan perfectly and prepare your body well, but if your mind hasn't been trained to manage the pain, failure is likely. This is simply about mental toughness. If you give in too easily and stop, or want some strategies to use when you can't quit, read on.
As cyclists, we all know the feelings that occur as the pace goes from moderate to more intense. When the workload becomes painful and the body wants to stop, we start searching within ourselves for the moment when we will give in.
Some days we can stick it out a little longer than others, but eventually we reach the point where we make the decision to pull off and slow down. Physically it feels good, but mentally we know we need to be stronger and be able to hold on longer before easing up.
Pain as a Trigger
Consider this: Instead of your mind being either on or off -- or in other words, instead of mindlessly following the group or maintaining an effort level in which your body asks your mind for permission to stop -- involve your mind much earlier. Do this by using the discomfort or pain as a trigger for several strategies.
In the book Sport Psychology for Cyclists, the authors suggest several strategies that I believe work well. Below I've summarized them into my own words, but I still suggest you read the book. You might only find one or two strategies that work well for you, but I strongly encourage you to experiment with them right now.