You have to keep focused on your goals. Personally, I found that whenever I was tempted to slack off, all I had to do was think "is slacking off right now really worth it? Do I really want to undo all of the hard work I have put in to get here?". Remembering all of your effort and keeping focused on your end goal (and all the good things that will come when you accomplish it) will really help.
I've also found it helpful to surround myself with people who support my goals and will help keep me on track if I start slipping. I had to step away from more than a few friends who were enabling my bad behavior, rather than helping me reach my objectives and better myself.
Keep strong and focused. Good luck!