You are the Boss:
Make them realise that things will happen according to your instructions. Register your presence in the class before starting the lecture. Take charge of your class and tell them that there will be no lecture until they are paying attention. Start with something interesting to lock their intention and then keep them engaged throughout the class.
Know your class:
You must know the psyche of your students. Give special attention to those who are not that interested in this learning process. That does not mean that you start shouting to show your disapproval to their attitude. The best thing is to walk all around during the lecture and stop near the problematic students. You may give them a shut up call by just taking a pause and looking at them during the lecture. If it is not working then you can ask them to change seats and sit with someone else.
Ask them what they want:
You should not impose your likes and dislikes rather ask them what they want to study. This is the best way to engage them during class as studying something of their own choice. Similarly, the disturbance in the class can be just because of some valid reason so try to figure it out nicely.
Give rewards and penalties:
Giving incentives can be really helpful in motivating them to stay connected. If someone does a good job then announce a reward and do give penalties in other cases. However, do think before giving punishment as your students can feel dejected and they won’t pay attention ever again.
You should give them little margin to do some monkey business. Do not turn your back rather establish eye contact with everyone.