This is a topic I've been working on for decades. When I was a younger athlete I would compete against EVERYTHING. Imaginary foes while I dug deeper in every rep of every workout. Go to any book store and you see all kinds of books on the psychology of sport.
Getting into the "zone" where time stands still and your mind is quiet is easy to do IF you know how to get there. This is one of the things I'm very good at and teach my athletes of how to tap into the zone while on the largest competitive stages. The zone is best exemplified by times you smash your hand or finger and later you say, "When did I cut myself?" Obviously, you were concentrating on something else and ignored the pain. Ah!
I won't go into full detail on how to get there... you'll just have to sign up for my coaching services to get that information. I will tell you some tips on how to relax mentally though.
1) Don't sweat the time:
Everyone who has raced at least once is worried about a PR. I have a few athletes who expect to PR in EVERY race. This is an unrealistic expectation. Some races are just a dress rehearsal for the BIG RACE later in the year. My question to those athletes is simple, "Do you want to PR here or at your qualifying race/A race?" Leave the personal baggage at the curb! Let GO of the expectations and just go out and execute on race day. Try racing without a watch, HRM or power meter; just once. I know you'll miss the data, but go out and try it. The freedom is awesome.
2) Have a plan on race day:
You should have rehearsed your race day plan SO MANY TIMES that on race day you can do it in your sleep. That's the idea. I'm amazed at how many people try different things on race day. WHY?! My best races are when I start to get hungry or thirsty and it is on the 15 or 30 - when a gel is due or a sip of something is timed. I smile on days like that. I know I'm crushing it.
3) Training on the days you feel like crap:
Doing the long training run/ride/swim when you feel like crap after a big week of training and eating right is the way you build that reserve of mental toughness for handling the "lows" of a triathlon. I tell all my Ironman racers to expect several times during the race when you'd like to throw your bike off the next hill or throw your shoes into a lake and sit down right there. Mental strength comes from those tough days as well as the correct mental talk in your head. MOST athletes DON'T HAVE THAT.
Spend time visualizing the race, the course, the experience. The sounds. The smells (good and bad). The feelings (air, water, ice). What you'll do when the proverbial shit hits the fan? What will you do when things go RIGHT? The finish- how will you finish? What will the finish line picture look like? A fist pump? A high five to a racer you just out sprinted?
5) Ego vs. YOU:
No matter what you've done to prepare for the race - you need to believe in yourself. At the end of the day, it's you vs. you. Here's a secret; you always win. Even as a pro, do your best on the day and if you PR and WIN great. IF you should PR and LOSE? CELEBRATE! You got beat, so what? A great example is the 3rd place finish at the Ironman World Championship a few years back of Tjorborn Sinballe - Think he's sad he "lost"? He just PR'd on the biggest stage of triathlon. Enjoy it. Enjoy the ride.
6) Surf the positive energy:
Smile. Encourage others - even if it is only a grunt. Positive works.
Tearing down others does not make you bigger. Build others up. Encourage others. You'll find the sledding easier and it is all mental.
Tough doesn't mean prison yard death stare. Tough is smiling at your competition when they glare at you. Moving your bike 1/2" when the Team in Training newbie freaks out yelling at you and the guy next to you for "being too close" in transition. Please. Smile anyway.
I think the results you have will be much easier and PRs more fun.