DENVER (KDVR) — Jack-o’-lanterns are an iconic symbol of Halloween today, and the tradition goes back centuries. But it wasn’t always pumpkins that people carved ghoulish faces into and stuck a candle inside before displaying them on the porch to rot.

The tradition of carving faces into vegetables in the fall dates back to the 1600s when people in Ireland would carve spooky faces into turnips and potatoes to scare off evil spirits.

They were targeting one evil spirit in particular. He’s called Stingy Jack, and he is described as old, drunk and miserable.

Stingy Jack: The spirit, the myth, the legend

Jack was mean, stingy, grumpy and a trickster. Elizabeth Stack, the Executive Director of the Irish American Heritage Museum in Albany, New York, told FOX Weather that he was mischievous and liked to play tricks on his neighbors, family and friends.

According to legend, Jack was even able to trick the devil, twice. Both times, Jack was on his deathbed waiting for the devil to come for his soul, Stack said. Then, Jack tricked the devil into giving him several more years of life.

This made the devil angry. When Jack was facing death for the third time, the devil refused to take his soul. God wouldn’t take him either since he lived a life of misery and cruelty.

“He was condemned to roam the earth, stuck between both heaven and hell,” Stack told FOX Weather.

But the devil left him with one thing — a glowing ember from the fires of hell.

Jack got a hollowed-out turnip and placed the bright ember inside, creating the first-ever jack-o’-lantern. Legend has it, he still uses the turnip lantern to light his way as he wanders Earth for eternity.

Thus he became known as Jack of the Lantern, and eventually, jack-o’-lantern.

Stack noted that there are different versions of the story. According to the Carnegie Museum of Natural History, Jack went as far as to trick the devil into changing his form and trapping him in his transfigured state. Jack used that leverage to make a deal with the devil to not take his soul.

The History Channel reports another version, in which Stingy Jack invited the devil to have a drink. Not wanting to pay, Jack convinced the devil to turn himself into a coin to pay for their drinks, and so he did.

Jack didn’t keep his word. Instead, according to the History Channel, he pocketed the money, along with a silver cross to prevent the devil from escaping. Jack made a deal to free the devil as long as he would not come back for a year and wouldn’t take Jack’s soul if he died.

A year later, Jack tricked the devil into climbing a tree to fetch some fruit. Then, Jack carved a cross into the tree bark while the Devil was in the tree so that he could not come down until he promised not to bother Jack for another 10 years.

“There were different versions, but basically they all agree that he was grumpy, possibly less than wholesome in his appetites; and he was mean, stingy, but also kind of mischievous,” Stack said.

Jack’s legend evolved into a tradition

The Irish began carving spooky faces out of potatoes and turnips in the 17th century, according to Stack. People would set those jack-o’-lanterns in windows and doors in an effort to scare away Stingy Jack, or whatever other evil spirits were wandering around in the fall while the veil between the living and the dead was at its thinnest.

Over time, the purpose of making lanterns out of vegetables shifted to help guide those celebrating Samhain, a Celtic festival celebrating the preparation of winter. During Samhain, according to the Carnegie Museum of Natural History, Celtics and Gaelics practiced a ritual of going from house to house in search of food.

Then came the Great Potato Famine of the 1840s. When Irish immigrants arrived in America, they brought the tradition to Halloween, this time using a new world crop that was much larger and easier to carve, pumpkins.

Today, carving pumpkins is a standard practice around Halloween in the U.S. Around this time of year, you’ll see the bright orange gourds on porches, used in beers, pies, cookies and lattes.