Writers like the Grimm Brothers and Robert Browning may have shaped the Pied Piper legend into art, but it turns out the story is likely based on an actual historical incident.

Every working morning for the last 26 years, Michael Boyer has slipped into a pair of neon-bright, multi-coloured tights, tied on his lipstick-red cape, grabbed his flute and marched out into the medieval streets of Hamelin, a town of 60,000 residents in Lower Saxony, Germany.

People sometimes mistake me for a superhero, court jester or Robin Hood

“People sometimes mistake me for a superhero, court jester or Robin Hood,” he laughed. He’s also increasingly become an Instagram prop for tourists and, maybe in some woke eyes, a gender-fluid statement.

But most people recognise him for what he is, the Pied Piper incarnate, appointed by Hamelin to impersonate its simultaneously favourite (at least commercially) and least favourite adopted son. Responsible for meeting and greeting visiting groups and dignitaries, he leads tours of the city and embodies the enduring hold of the legend that draws most travellers here.

The tale in fact has survived for a very long time. Originating as medieval folklore, the story inspired a Goethe verse, Der Rattenfänger; a Grimm Brothers’ legend, The Children of Hamelin; and one of Robert Browning’s best-known poems, The Pied Piper of Hamelin. And although each writer tinkered with the story, the basics remained the same: the Piper was hired by Hamelin to rid the town of its plague of rats. Trailing after the hypnotic notes of the rat-catcher’s magical flute, the rodents politely filed through the city gates to their presumed doom.

They weren’t the only ones lured by his music, though. When the town refused to pay the Piper for his service, the saviour turned into a more satanic seducer and came for Hamelin’s children. Entranced by the notes of his flute, the transfixed boys and girls followed the Piper out of town and simply vanished.

While the tale has endured, so has Hamelin itself, which still looks as though it belongs in a fairy tale. Boyer’s tour leads visitors past rows of half-timbered houses. There are 16th Century burgher manors encrusted with Gothic gables and scrollwork, and flamboyant wedding cake buildings offering prime examples of the local Weser-Renaissance architecture, all leering gargoyles and brightly coloured polychrome wood carvings.

However, all this is merely background for the town’s real cottage industry, which cashes in on all things Piper. The local restaurants plate a “rat tail” signature dish made from thinly sliced pork, and the bakeries do a brisk business in rodent-shaped breads and cakes. The Hameln Museum offers a sound and light Pied Piper re-enactment; local actors put on an open-air Pied Piper play during summer; and the souvenir shops hawk their own rat-inspired memorabilia. You can go home, if you wish, loaded down with Pied Piper T-shirts, fridge magnets, mugs and flutes.

What could pass for mere comic relief, though, masks something deeper, and suggests why the legend lives on not only in Hamelin but in enduring folklore. On some level, the tale stokes a primal fear, with the Piper a version of a universal bogey man that continues to haunt us. Parents everywhere still fear the loss of their babies. Children, popping up on the nightly news, still go missing every day. And then we all ultimately vanish in something like an instant. The Piper, in the end, is one very grim reaper.

But if the tale evokes a universal fear, it still resonates most strongly in Hamelin – and the Piper’s tour suggests why. In fact, the real surprise of his tour isn’t so much the beautifully preserved townscape but the suggestion that the Pied Piper is much more than just a fairy tale. The Grimm Brothers and Browning may have shaped the legend into art, but the story, it turns out, is likely based on an actual historical incident.

You may also be interested in:
The elusive hidden people of Iceland
Is it time to rewrite fairy tales?
How a German city changed how we read

The proof is etched on Hamelin’s face itself. An inscribed plaque on the stone facade of the so-called Pied Piper house, a half-timbered private residence dating to 1602 – similar to an even earlier one etched on the building’s window – bears explicit witness to the mystery. The inscription reads:

“A.D. 1284 – on the 26th of June – the day of St John and St Paul – 130 children – born in Hamelin – were led out of the town by a piper wearing multicoloured clothes. After passing the Calvary near the Koppenberg they disappeared forever.”

The inscription isn’t the only clue. An entry in Hamelin’s town records, dating to 1384, laments that, “It is 100 years since our children left.” The stained-glass window in the town’s St Nicolai church, destroyed in the 17th Century but described in earlier accounts, reportedly illustrated the figure of the Pied Piper leading several ghostly white children. And the 15th Century Luneburg manuscript, an early German account of the event, along with five historical memory verses, some in Latin and others in Middle Low German, all refer to a similar story of 130 children or young people vanishing on the 26 June 1284, following a pied piper to a place called Calvary or Koppen.

The Pied Piper then, more than a fairy tale, becomes the emblem of a profound historical mystery. What happened to the missing children of Hamelin? Still the master seducer, the mesmerising rat-catcher is now leading a whole new trail of entranced followers – this time a conga line of historians each taking their own deep dive into the question of what exactly transpired in Hamelin on 26 June 1284.

In this scenario, the Pied Piper played the role of a so-called locator or recruiter

The theories are legion, according to Wibke Reimer, project coordinator at the Hameln Museum who has been organising a special exhibit that focuses on the global reach of the Pied Piper legend. One of the leading current theories suggests the town’s youth were part of a migration of Germans to Eastern Europe fuelled by an economic depression.

“In this scenario,” Reimer said, “the Pied Piper played the role of a so-called locator or recruiter. They were responsible for organising migrations to the east and were said to have worn colourful garments and played an instrument to attract the attention of possible settlers.”

While some historians believe that the youth emigrated to Transylvania, the German linguist Jürgen Udolph’s theory is most accepted. “He suggests the regions around Berlin as the most probable location, in an area that’s now [eastern Germany],” Reimer said, “and he backs up his theory by place name evidence.” In fact, Udolph found that the family names common in Hamelin at the time show up with surprising frequency in the areas of Uckermark and Prignitz, near Berlin, that he locates as the centre of the migration. The theory is also reinforced by evidence that the region, newly liberated from the Danes, was ripe for German colonisation. 

More fanciful theories abound, too. Some historians suggest the legend reflects a 13th Century children’s crusade, part of the wave of medieval crusades aimed at winning back the Holy Land. And some argue the youth were lost to the Black Plague, though the dates don’t match up.

More intriguing is a theory that points to the medieval phenomenon of “dancing mania”, driven by a succession of pandemics and natural disasters. Known as St Vitus’ Dance, the dancing plague is documented surfacing in continental Europe as early as the 11th Century. A form of mass hysteria, the dance could spread from individuals to large groups, all driven by an unshakeable compulsion to dance feverishly, sometimes for weeks, often leaping and singing and sometimes hallucinating to the point of exhaustion and occasionally death, like a top that can’t stop spinning.

And, in fact, one 13th Century outbreak – a literal form of dance fever – occurred south of Hamelin, in the town of Erfurt, where a group of youths were documented as wildly gyrating as they travelled out of town, ending up 20km away in a neighbouring town. Some of the children, one chronicle suggests, expired shortly thereafter, having flat-out danced themselves to death, and those who survived were left with chronic tremors. Perhaps, some theorise, Hamelin witnessed a similar plague, dancing to the figurative tune of the Piper.

But all these theories neglect one specific key to the Hamelin mystery. “They don’t explain the very particular date cited for the loss of the children, and the local sense of trauma,” Reimer noted. “Did something happen that officials had been covering up? Something so traumatic that it was transmitted orally for so long in the town’s collective memory, over decades and even centuries?”

In fact, the date chronicled in all the local documentation pinpoint 26 June as the day the children disappeared. This day is also the date of pagan midsummer celebrations. The fact the documentation also emphasises that the youth followed the Piper to the Koppen, commonly translated as “hills”, suggest another link. “There were regions in Germany where midsummer was celebrated by lighting fires on the hills,” said Reimer. All that leads to one particularly macabre reading of the Pied Piper legend. Perhaps the Piper, emblematic of a pagan shaman, playing his flute, was leading the youth of Hamelin to their midsummer festivities when the local Christian faction, hoping to cement conversion of the region, waylaid and massacred the group. A less bloody theory: maybe the children were spirited away to local monasteries.

If the tale suggests a possible historical tragedy, though, it also offers an artistic redemption as well.

“The Pied Piper story,” said Reimer, preparing for the debut of her exhibit on 26 June, “is to our knowledge known in at least 42 countries and 30 languages, maybe more. And it appears in international art, literature and music. The Pied Piper is a shared heritage of many people, and that cultural heritage connects people.”

Ultimately, then, the Piper didn’t just fracture a community. He also, in the end, brought a larger one together.

Join more than three million BBC Travel fans by liking us on Facebook, or follow us on Twitter and Instagram. 

If you liked this story, sign up for the weekly bbc.com features newsletter called "The Essential List". A handpicked selection of stories from BBC Future, Culture, Worklife and Travel, delivered to your inbox every Friday.