Both the first climber, the leader, and the following climber, the belayer firmly attach the rope to their climbing harness. As such, the leader, is roped from below, so has relatively little assistance in a fall; though judicious placement of anchoring points can mitigate this problem somewhat. Since the belayer is protected by the rope held from above by the leader, he/she is relatively safe.
The belayer will have some means of controlling the amount of slack in the rope; they need to be able to pay out more rope if the climber moves away from them, take in slack if the climber moves towards them, or hold the rope to arrest the fall should the climber fall.
Usually the belayer will achieve this by using a belay device attached to the harness through which the rope runs. A climbing eight is a popular belay device. The eight allows the belayer to control the amount of friction applied to the rope, which varies from very little when the rope needs to move, to enough friction to stop a fall. There are many varied belay devices: gri gri, sticht plate, tuber (climbing), various proprietary trade names. Some climbers do not use a belay device, a sliding knot known as the italian hitch (also known as friction hitch or muenter hitch) can be used.
The protection that climbers use varies but the basic idea is to run the rope through a point that is secured to the rock; if the leader should fall they will fall twice the distance from them to their last piece of protection that stayed in place (plus the stretch of the rope), hopefully this is a sufficiently short distance to prevent them from hitting any large ledge or the floor.