The first thing you do is the most critical piece.
Stop and take a deep breath.
It's going to be ok!
"Workouts gone wrong" where you don't hit your target pace or distance or effort will happen when training for a triathlon. The important thing is what you do after.
After taking a deep breath (and wiping to tears), think through what went wrong and why. Was it nutrition? Temperature? Stress from work? Bad sleep? Poor hydration? It can be any number of things, but it's important to narrow it down to one to two causes why the workout went south.
Make a note of it in your training log, you are more likely to remember something if you write it down. And the next time a similar workout is coming up review that note!
Next, remember how many more workouts are to come! One bad workout won't make or break your race. Not learning from a bad workout might though.
What not to do? Try to go right back out the next day and repeat the workout as "it should have been". That workout is done, learn from it and move on to the next.
Lastly, take a deep breath and remember it's going to be ok! Triathlon is about consistency over time, not crushing it (or being crushed) every now and then.