Many cultures and religions have contributed bits and pieces to the holiday we now know as Halloween. The earliest such celebrations let Celtic and Roman pagans honor their dead ancestors, make peace with ill fortune, and prepare for the dormant winter season. When Europe was Christianized, these festivities were appropriated by the Church to honor Saints and the deceased. Finally, waves of immigrants from Ireland and Scotland brought traditions to America that coalesced in the mid-1900s as the mischief, costumes, and sweets we're familiar with today.
The Celts celebrated the end of summer with their New Year around the autumnal equinox on November 1st. These were ancient people, living around 0 CE, in modern day Scotland, Ireland, and Wales. The coming bleakness of winter meant the festival was on the cusp between life and death. On this occasion, Druids believed the boundary between the dead and living was malleable. The night before, October 31st, they celebrated Samhain to honor those ancestors returning to the realm of the living. Thus, while common folk celebrated costumed like sacred animals and danced around bonfires, the Druids conducted divinations to predict the future.
During the same era, Roman Pagans celebrated a similar festival to celebrate the dead, called Feralia. Instead of focusing on winter, this was a time of harvest, full of ripe fruit and plentiful food from the goddess Pomona. From this, we borrow our apple-bobbing and cornucopias associated with Halloween. When Christianity swept through Europe, the church had to convert these pagan holidays to holy days of worship. Thus they created All Saints' Day to fall on November 1 to replace holidays associated with death. When this was ineffective at fully converting everyone, around 1000 CE the church declared November 2 to be All Souls' Day so that people could acknowledge their deceased.
From All Saints' and All Souls' Day, we derive the name Halloween. In middle English, All Saints' Day translates as Alholowmesse, which was handed down as All Hallow's Evening and abbreviated as Hallowmas or Hallowe'en.
Other customs associated with Halloween have been very recently adapted. The general sense of children's mischief arose since parents could easily blame it on "ghosts" visiting for the night. Collecting candy and sweets from neighbors was originally a way of gathering offerings for All Souls' Day. A Jack-o-lantern used to be a carved turnip with a candle inside that was placed in windows to ward off evil spirits. The Irish story goes that stingy, sinful Jack makes the Devil promise he won't be taken to Hell. Jack must return to the Devil when he's rejected from heaven. The Devil gives him a burning ember to place in a carved-out turnip to light his way as a wandering soul. Pumpkins, since they are a squash and not a root, are easier to carve, so Irish immigrants in America preferred them over turnips.