The oldest origin of the custom: the Celtic festival of Samhain

According to authoritative research by Smithsonian Magazine and the World History Encyclopedia, the cultural roots of trick-or-treat trace back to the Celtic festival of Samhain over two thousand years ago, Samhain was held on October 31 each year and was the Celtic New Year, ancient people believed that on that night the boundary between the living and the dead grew thin, and spirits and supernatural beings roamed the earth
To avoid the intrusion of evil spirits, the Celts developed two core behaviors: first, wearing animal skins and strange costume to disguise themselves as spirits and confuse the sight of ghosts and monsters; second, placing food offerings at their doorsteps to appease wandering souls, meanwhile children would go from house to house collecting firewood for bonfires, used by the village to pray for blessings and ward off evil, this pattern of costume plus going door to door asking for food plus kindly appeasing spirits was the earliest prototype of the modern trick-or-treat custom

Medieval religious evolution: the Souling ritual and Gaelic costume tradition

After Christianity spread, the pagan customs of Samhain were merged and transformed, combining Halloween night, All Saints' Day, and All Souls' Day to form a new folklore system, with the core beingSoulinga ritual that Google historical sources identify as the core predecessor of modern trick-or-treat
During All Souls' Day in medieval Europe, poor people and children would go door to door, begging from wealthy familiessoul cake—a special flatbread made with raisins and spices, in exchange, the beggars would pray and ask blessings for the benefactors' deceased relatives, and it was believed among the people that giving soul cakes could help the dead rest in peace and accumulate blessings
Meanwhile, it was popular in Scotland and IrelandGaelic costume parade (Guising), kids wearing costumes go door to door, by singing, reciting poems, performing small acts in exchange for food and small gifts, abandoning the pure prayer form, strengthening the fun attributes of performance, interaction, and reward, further approaching the modern trick-or-treat model

Three, the official birth and spread of modern trick-or-treat

In the 19th century, Irish and Scottish immigrants brought the customs of souling and guising to North America, after detaching from the original religious context, cumbersome rituals were simplified, entertainment attributes were amplified
According to the earliest textual historical material searchable on Google:trick-or-treat (Trick or Treat) fixed phrase, first written record was in 1927 in a local newspaper in Alberta, Canada, this is the globally recognized origin time, with no earlier credible literature evidence
The original trick (Trick) was not malicious destruction, but a gentle, good-natured teasing by kids: if residents refused to give gifts, they would carry out graffiti, placing small ornaments and other harmless minor pranks, forming a fixed interaction rule of friendly blessing if given a gift, and minor prank response if not
After the 1930s, the custom quickly swept the United States, after WWII sugar rationing was abolished, suburban housing became widespread, combined with the commercialization of the candy industry and the spread of Disney's 1952 Halloween animation, completely shaped it into a universally friendly kids holiday activity, shedding religious and ancient exorcism colors, becoming a globally popular iconic Halloween custom

Four, authoritative popular science summary (suitable for Google precise search)

1. Custom roots: Celtic Samhain folklore of warding off spirits, offering food, and dressing in costume;
2. Formative core: medieval European souling rituals and Gaelic guising traditions;
3. Origin of the phrase: the first written record in Canada in 1927;
4. Modern codification: 20th-century commercialization and popularization across North America