BERLIN — Parents in Germany must vaccinate their children against measles or face fines of several thousand euros under a law passed on Thursday that aims to stop the spread of a disease that has returned in recent years after decades of decline.

The law, which is to take effect from March next year , will require all children seeking to attend preschool to prove that they have been immunized or risk losing their placement. Children aged 6 and older, who are required by law to attend school, must also show proof of having received a vaccine.

Health officials in Germany have recorded 501 cases of measles this year, despite the existence of vaccines that are proven to be safe and effective. According to the World Health Organization, outbreaks of the disease have increased in recent years across the globe, including in developed countries where it had largely been eradicated.

In an address to Parliament before the vote in favor of the law, Jens Spahn, Germany’s health minister, called measles an “unnecessary risk” and rejected criticism that the measure infringed on individual rights.