Setting a budget, and sticking TO a budget, are different things.
A good tip in setting up a budget is to not allocate all of your yearly income to the budget. For example: I get paid every two weeks, which means 26 paychecks a year. However, my budget is set up so that I assume I only get 2 paychecks per month, which is true most of the time. The two "bonus" checks are completely outside of the plan as a nice cushion in case something completely unexpected comes up -- car repairs, appliance failure, etc. If all goes well, then it's extra money in the bank.
Along the same lines, don't allocate all of your MONTHLY income to the budget, either. You should include line items for mandatory savings/investment contributions, and sometimes it makes sense to include an item labeled "cushion" as a fudge factor if you're not 100% sure about your estimates.
Many budgets fail because they are not realistic. Utility bills are easy to figure out -- average the last 4-5 to get a feel for the baseline -- and things like rent and car payments are fixed. Also, don't forget to calculate what you need to pay towards your credit cards to not just keep up with monthly minimums, but to knock them down to zero over time. However, most people have little feel for how much they spend on food, gas, and small discretionary items -- "oh, I'll just pick up a CD while I'm out." Track what you spend over the course of a week or two, and you'll be surprised how fast those things add up.
What do you do if you find yourself overspending your budget? The single best thing you can do is to track your spending on a weekly basis -- it's a best practice for management, and it works in your personal life too. When you see how fast you're burning through the discretionary part of your income, you can slow down so you don't go over your budget by the end of your month. If you find that you need to cut some corners, there are some classic places to look: cell phone plans, "fun" purchases like CDs/books/games, eating at home vs. eating out, and so on.
Oh, one more thing. Debit cards can be deadly since you don't "feel" how much money you're spending. If you only allocate, say, $100 in "pocket money" for the week in your budget, then stop at the ATM on Sunday night and take out the $100 in cash. You won't have to look any farther than your wallet to know how you're doing on your plan.
The bottom line is that saying "no" to a purchase requires discipline, and there is no getting around it. By reminding yourself about your financial status and your goals, though, it's easier to make the right choice.