This very popular Shivaratri legend from Puranas explains why people stay awake all night on Shivaratri. Besides, it also tells us why Lord Shiva is also known as Neelakantha.
Once Indra – the King of Gods, while riding on an elephant came across Durvasa Muni who offered him a special garland. Indra accepted the garland but put in on the trunk of the elephant. The elephant was irritated by the smell and it threw the garland on the floor. This enraged the sage as the garland was a dwelling of Sri (fortune) and was to be treated as prasada. Durvasa Muni cursed Indra and all devas to be bereft of all strength, energy, and fortune.
In battles that followed this incident, devas were defeated and asuras (demons) led by Bali gained control of the universe. Devas sought help from Lord Vishnu who advised them to treat asuras in a diplomatic manner. Devas formed an alliance with asuras to jointly churn the ocean for the nectar of immortality and to share it among them. Lord Vishnu told Devas that we would arrange that they alone obtain the nectar.