The first foods that were considered desserts were dried fruits and honey and were fed to the gods in ancient India and Mesopotamia. The largest development of dessert came with the spread of sugarcane which was grown before 500 BCE.
With the introduction of sugarcane to the world, sugar became a staple of cooking and desserts for over a thousand years and continues to be today. Desserts were introduced as a sweet treat after dinners to help cleanse the pallet and end the meal with something to help to boost moods. Finishing the meal with a sweet treat was shown to boost morale.