I think your not a failure. You accomplished your goal and finished out your day. You knew when you needed to leave to calm yourself down and you did that and you were able to go back into work and work another 5 hours. Good job.
Always remember this, no one is perfect. You are who you are and you make the best of it. You did the right thing and I am proud of you. Good job