There are several factors that are thought to have ended the plague, or Black Death, but the most important appears to be measures taken by people to quarantine themselves. Better hygiene also helped.
To avoid catching the plague people were advised to stay away from infected people. They were also advised to avoid activities that were known to open the pores in the skin. This included sex, exercise and bathing. While the theory behind this was wrong, the practice did help. But the quarantining measures that were employed are widely believed to have been the most effective.
They resulted in many people leaving cities for the cleaner air of the countryside. The disease spread less rapidly there than it did in cities where people live close together. Sometimes, people were quarantined in their houses to prevent them from infecting others, but most of the quarantine actions were taken by healthy people to keep themselves away from others who might be sick.
Better hygiene is also thought to have helped societies beat the plague. This involved washing in clean water, boiling water before drinking it and reducing the practice of burying the dead in mass graves.
Finally, apart from moving to the countryside where possible, people stopped traveling as much. Instead the chose to stay in places that they knew were safe and free from the disease.