Beginning at sundown on March 4, Jews around the world will celebrate Purim, a holiday often compared with Mardi Gras for its feasting, drinking and masquerading.

The roots of Purim, as related in the Biblical Book of Esther, go back to ancient Persia, where the Jews were prosperous and prominent. King Ahasuerus, believed by scholars to be Xerxes I, had taken as his queen the beautiful Esther, who hid her Jewish identity from her husband.

Her uncle, Mordechai, an adviser to the king and leader of the Jewish community, angered Haman, the king’s grand vizier, when Mordechai refused to bow before Haman. Through lies and slander, Haman convinced the king to sign a decree ordering the killing of all the Jews of Persia on the 13th day of the Jewish month of Adar, a date selected by pur, or lots.

Using a carefully planned strategy, the queen hosted a dinner for the king where she revealed that she was Jewish and what Haman’s evil plot really meant. The king revoked the decree and ordered Haman hanged from gallows he had built to hang Mordechai.

For thousands of years, Jews around the world have celebrated Purim on the 14th day of Adar. The day, which usually falls in March, begins with the reading of the Book of Esther. Children dress in costume as Esther, Ahasuerus, Mordechai and Haman, whose name is drowned out with special noisemakers every time it is mentioned.

The celebration usually includes a festive meal in the late afternoon, donations of charity to the poor and edible gifts to friends and neighbors.

According to food writer Joan Nathan, a variety of baked goods is prepared as Purim gifts, but these are always given with fruit. This gift tradition, called shalach manot — meaning portions delivered by messenger — is often extended to elders in the community and to those who are ill and cannot leave home. The custom is for children in the family to assemble and deliver these trays and baskets to learn the importance of good deeds.

“The foods associated with this holiday vary from country to country,” writes Judy Zeidler, author of “The Gourmet Jewish Cook.” “Baking begins weeks in advance, because sharing delicious baked goods with less fortunate people is an ancient custom.”

The most traditional Purim treat is the hamantaschen, a three-cornered filled pastry, often said to represent Haman’s hat.

The traditional filling is poppy seeds, but bakers from around the world use hundreds of different fillings, including jellies, dates, chocolate mixtures and even cheese.

According to Rita Milos Brownstein, author of “Jewish Holiday Style,” hamantaschen dough is a subject of debate among Jewish cooks.

“Purists prefer the traditional dense, cakelike dough, while others roll out a thin, crisp pastry, almost like sugar cookie dough,” she writes.

Fillings, too, differ from community to community and from home to home. “Traditional poppy seed and prune paste have moved over in recent years to make room for apricot, raspberry, peanut butter, date and even chocolate chip fillings,” she writes.

Purim is a most joyous occasion, but beneath the facade of the day of feasting and celebrating is the lesson of the story of the evil Haman — the fear that intolerance and persecution can happen in any society at any time.

“Although the Jewish people have faced many Hamans since the day of Ahasuerus, this chapter in our history gives us strength to face them all and always to survive,” Brownstein writes. “We celebrate for those who came before us, and we celebrate with our children so they may teach those who come after us.”

Among the recipes for Purim, or any festive occasion, which follow are a traditional hamantaschen and an assortment of fillings that can be used.