Be prepared. Have your first aid kit ready to be put into action.
If you go into a diet realizing that you will probably make mistakes, sometimes without meaning to, then it won't throw you so much when it happens.
Thinking about this beforehand gives you more self control. You can say to yourself: If and when I overeat, or eat the wrong thing, then I'll do such and such.
It is not slipping off your diet plan that causes you a problem. It is your reaction to the slip that causes the most damage to your self-esteem and also to your weight loss motivation.
Being armed, being prepared, knowing that something can be done in the face of momentary failures, reduces the stress caused by these all too common slips. It allows you to cope much more effectively so you can come out of a setback with your diet intact again.