The TARDIS lands in the town of Hamelin in 1284, in the realm of the Pied Piper within the Koppelberg Hills. Dr. Who, John and Gillian meet the children of Hamelin, who were taken away by the Pied Piper after the Mayor of Hamelin refused to pay him the promised thousand guilders for ridding the town of rats. The children now want to go home, so Dr. Who and his grandchildren go to see the Pied Piper to try to persuade him. But the Pied Piper will only do this if Dr. Who takes and passes three tests. If Dr. Who succeeds, the children can go home; if not, Dr. Who and his grandchildren will be imprisoned in the Pied Piper's castle dungeons for the rest of their lives. Dr. Who uses technological tricks to pass the test, and then leads the children back to Hamelin. The Mayor gives Dr. Who the thousand guilders for the Pied Piper (after Dr. Who threatens to take the children away again), but when Dr. Who and his grandchildren return to the cave in the Koppelberg Hills, they discover the Pied Piper and his realm have vanished. Before they leave in the TARDIS, Dr. Who leaves the bag of coins in the cave in case the Pied Piper comes back to look for it.
- The Doctor encounters a dragon in the Pied Piper's realm. He uses a fire extinguisher to drive it off.
- The Pied Piper's realm contains toffee apple trees, lemonade fountains and barley sugar groves.
to be added