The Irish story of the Jack-O-Lantern is about “Stingy Jack” who played tricks on the Devil. He played so many that he got the Devil to promise him not to take his soul to hell upon death.
However, he was also unable to enter heaven when he died because of the horrible life he led and his deals with the Devil.
So Jack was forever banished to the darkness between heaven and hell. The Devil gave him an ember from hell inside a hallowed out turnip to help guide his way in the darkness.
Eventually, people started putting carved-out turnips on their porch steps to ward off Jack and any other evil roaming spirits.
Once the tradition came to America, they found the pumpkin to be a better fit.