What do I do if my 2-year-old breaks a rule?

Consistency. At this age, children often say "no" or refuse to do what you want them to do. This normal phase of development involves testing the rules that parents make. Parents need to be consistent in following through with reasonable rules. Your rules should not be too strict or too lenient. Enforce the rules fairly every time. Be gentle but firm with your child even when the child wants to break a rule.
Timeout. This is a good age to institute time outs, and time-ins. Immediately after the unwanted behavior take your child aside and tell them what was wrong, place them away from activites and distractions for a couple minutes. Time in is immediate praise after good behavior.
Behavior probs. I published a book on kindle that i think will really help you. It is called: parenting the kids according to a child psychiatrist. It is only $5.95 and i think it will help you a lot, to get your child to behave much better right away. Good luck to you.
Time-out. If a rule is broken, after a short, clear, and gentle explanation, immediately find a place for your child to sit alone for 3 minutes. It is very important that a "time-out" comes immediately after a rule is broken. Time-outs can serve as an excellent tool to teach a child a rule. Time outs require skill and careful planning. If you use the time-out technique, be sure to read about it first.
C and P. Explain the rule, even to a 2 y/o. Explains the benefits of following the rules and the consequences of breaking them.Then follow thru every time there is an infraction. Be consistant and be persistant. With patience and 2-3 weeks there is almost always an improvement.