Despite its origins in pagan and Christian tradition, the modern American Halloween is often a purely secular celebration centered on candy and costumes. But in fact, one of the most frivolous aspects of the holiday has a serious religious past.
Medieval Christian tradition held that on Hallowtide, the eve of All Saints’ Day, the poor went to the homes of the wealthy and offered to pray for the recently departed in that household. It was believed that more prayers meant a soul was more likely to be saved, explains historian Nicholas Rogers, author of Halloween: From Pagan Ritual to Party Night. As a token of their appreciation, the rich would give the poor food and beer.
In fact, many Halloween customs come from this same ritual. For example, often the visitors would show up holding lanterns made of hollowed-out turnips with candles inside, which represented souls in purgatory. Masses were held so that souls wouldn’t feel neglected and haunt believers. A medieval English historian named John Stow reported there was “subtle disguising, masks, and mummeries” — so, costumes — and in some cases choir boys dressed as virgin brides, representing forthcoming marriages that would lead to more births and the replenishment of the Christian population.
Get your history fix in one place: sign up for the weekly TIME History newsletter
But after the Protestant Reformation — which can be traced back to a different Oct. 31 event: Martin Luther’s 1517 publication of his 95 theses — the idea that souls could be saved in this way began to lose popularity in many of the new denominations.
Some Catholics kept up the practice of going door-to-door on the eve of All Saints’ Day, which became known as “souling.” By the 1840s, when a wave of Irish and Scottish immigrants brought the custom to the U.S., it was basically a secular pastime associated with that immigrant population. Young people danced outside tenement apartments in exchange for gifts, leading into a night of drinking and revelry in the streets and in bars. Costumes were made out of old clothes, and faces painted with burnt corks, while tricks included stuffing cabbages in chimneys and whacking each other with bags of flour.
Although the Catholic Irish faced widespread prejudice from nativist forces in their new homeland, the celebration, having been stripped of its Catholic underpinning, quickly proved to be popular. As those immigrants began to assimilate, newspapers reported the custom trending among 19th century college students. In the early 1900s, high schools, rotary clubs and charities began to throw Halloween parties, and guidebooks about how to host such celebrations came out. By the 1930s, North America had a new term for the old tradition: trick-or-treating. And as suburbanization grew in the 1950s, trick-or-treating grew into the kid-friendly practice it’s largely seen as today.