Dont lose hope. Every failure teaches you something, to become more stronger and to never give up. You will face these situations in real life also, the easier choice is to step back, but the most difficult one is to face and overcome the challenge. But at the end of the day the satisfaction you get when you fight back is tremendous.
I suggest you to take a break (a weeks time to get over it). With a calm mind sit down and analyze what went wrong. Where are you losing marks, where do you have to put more effort, what is it you can do differently etc. Have faith in yourself and put that 'extra' effort, I am sure success will come to you soon.