The Story behind lighting these 365 wicks: King Hima’s sixteen-year-old son was destined to die by snakebite on the fourth day of his marriage. On the fourth day, his wife did not allow him to sleep. She laid out ornaments & heaps of gold at the entrance of her husband’s chamber & lighted lamps all over the place. She spent the night telling stories & singing songs.When Yam, the God of Death arrived in the disguise of a serpent, his eyes were blinded by the sparkle of the lights & he could not enter the prince’s chamber. Instead, he climbed on top of the heap & sat there the whole night listening to the songs. In the morning, he went away & it was on that night that her husband was saved from death. This day is also known as Yamadeepdan & lamps are kept burning throughout the night, in commemoration of Yamraj.
Source:http://www.lohana.info/Culture%20Corner/Diwali.pdf