The word itself, "Halloween," actually has its origins in the Catholic Church. It comes from a contracted corruption of All Hallows Eve. November 1, "All Hollows Day" (or "All Saints Day"), is a Catholic day of observance in honor of saints. But, in the 5th century BC, in Celtic Ireland, summer officially ended on October 31. The holiday was called Samhain (sow-en), the Celtic New year.
One story says that, on that day, the disembodied spirits of all those who had died throughout the preceding year would come back in search of living bodies to possess for the next year. It was believed to be their only hope for the afterlife. The Celts believed all laws of space and time were suspended during this time, allowing the spirit world to intermingle with the living.
Naturally, the still-living did not want to be possessed. So on the night of October 31, villagers would extinguish the fires in their homes, to make them cold and undesirable. They would then dress up in all manner of ghoulish costumes and noisily paraded around the neighborhood, being as destructive as possible in order to frighten away spirits looking for bodies to possess.
Probably a better explanation of why the Celts extinguished their fires was not to discourage spirit possession, but so that all the Celtic tribes could relight their fires from a common source, the Druidic fire that was kept burning in the Middle of Ireland, at Usinach.
Some accounts tell of how the Celts would burn someone at the stake who was thought to have already been possessed, as sort of a lesson to the spirits. Other accounts of Celtic history debunk these stories as myth.
The Romans adopted the Celtic practices as their own. But in the first century AD, Samhain was assimilated into celebrations of some of the other Roman traditions that took place in October, such as their day to honor Pomona, the Roman goddess of fruit and trees. The symbol of Pomona is the apple, which might explain the origin of our modern tradition of bobbing for apples on Halloween.
The thrust of the practices also changed over time to become more ritualized. As belief in spirit possession waned, the practice of dressing up like hobgoblins, ghosts, and witches took on a more ceremonial role.
The custom of Halloween was brought to America in the 1840's by Irish immigrants fleeing their country's potato famine. At that time, the favorite pranks in New England included tipping over outhouses and unhinging fence gates.