I vaguely remember watching a cartoon movie whose plot goes like this.
The movie begins with a boy named Hans and a girl (I don't remember the name) playing on a meadow. The girl's kite gets trapped on a tree, and she asks Hans to climb on the tree and free that kite. Hans refuses to do that unless the girl gives him money. The girl says she has no money, so Hans suggests her to promise that she will give him money and that they shake their hands so that promise won't be forgotten. They shake their hands, but it turns out that Hans has a frog in his hand, which causes the girl to freak out.
When they return home, an old man puts the two children in a bed and tells them a story from his childhood. The cartoon then "switches to the past": the picture follows the story, rather than showing the old man telling the story and the children listening to it.
So, a town is infested by rats. Some kind of a senate gathers to decide what to do about it. There comes a tall man in weird clothing and promises them he has a solution. Skeptical, they tell him to try.
A boy called Peter and a girl follow that tall man in wierd clothing into a forest, and he tells them: "Are you looking for somebody, children?". Peter asks him how he is going to free the town from the rats, and he tells them that he will do that with music. Children look confused. The tall man in weird clothing grabs a knife, cuts a bark of some tree, and makes a flute out of that bark. Peter says: "A flute? That's just a flute. Flute will not free us from the rats.".
However, the man starts playing that flute in the town, and the rats follow him. He leads them toward a river, where the rats drown.
The town senate meets again. The man asks for 200 pieces of gold. The mayor of the town (?) says that's too expensive, and suggests to give him half of that or less. Some people in the senate suggest not giving him any gold at all. So the man says he will punish them. The mayor says: "You won't return the rats to us?". The man says: "Oh, no. Something much worse than that! See you later!". The mayor says: "What can possibly be worse than rats?".
The man starts playing his magic flute again, but this time, instead of rats, children start following him. Peter, this time with an injured leg, decides not to follow him, and to warn the town of the situation. Peter tries to ring the church bell, but the man somehow (I don't remember the details) prevents him from doing that.
The man leads a lot of the children from the town deep into the forest, and leaves them there. Luckily, Peter somehow finds them and leads them back home.
The movie ends, if I remember correctly, with Hans saying that his grandfather was called Peter and that he supposes his grandfather was that Peter from the story.
Does anybody recognize the movie? Attempting to Google it led me to the Wikipedia page about the Pied Piper legend, which claims there are dozens of movies with that same theme.