In teaching students, classroom management is key to keeping students focused and on task. With unruly students, I first talked to the student privately to find out the problem. Maybe they didn't understand course material, and setting up a private signal for "I don't get it" would help. Sometimes, depending on the age of the students, parental contact would help. In addition, I talked to other teachers of the same student to find out what worked for them or was it only happening in my class and why. If the behavior was happening often, I checked in with the school counselor, nurse or police liason officer looking for other reasons which would help me figure out a course of action. Changing the arrangement of my room or seating charts sometimes would help. If none of the above worked, I simply had referral slips to the office signed and on my desk; when the behavior began, I sent them to the hall where I gave them the choice to return and behave or leave immediately for the office. Above all, don't take the behavior personally or let them see your frustration; keep a calm voice and let them choose.
Your first step is to familiarize yourself with the policies and support systems of your particular school. Every school has guidelines to which you must adhere.
The second most important thing is to remain calm and think of the behavioural issues not as a personal challenge or insult but simply as part of the practical daily task of classroom management.
Your top priority is ending any behaviour that affects other students' learning. You can sometimes do this simply by changing seating arrangements -- moving the friends who are gossipping together to opposite sides of the room. Sometimes asking the students questions about subject matter will get them back on track. For persistent offenders, you may need to report the behaviour to higher administrative levels.
Avoid giving unruly students excessive attention or showing that they are upsetting you, for that will re-inforce the bad behaviour.