One of the scripts explains that Shivaratri came into existence during Samudra Manthana when Lord Shiva drank Halāhala(which is the name of a poison created from the sea when Devas (Deities) and Asuras (Demons) churned it to obtain Amrita, the nectar of immortality.
The festival maha Shivaratri is also celebrated to mark the day on which Lord Shiva married Goddess Parvati.
The story about Shivaratri is narrated in Garuda Purana. Once there was a hunter named Suswara. He had been for hunting, as usual, one day when he did not get anything till dusk. In remorse over the fate that his wife and children would be hungry if he returned empty-handed, the hunter climbed up a tree to spend the night.
A little while after dusk, the hunter spotted a deer and wished to kill it. However, when he saw that the deer was feeding its fawns, he felt killing the deer would deprive the little ones of the motherly care, and therefore he spared it.
The tree on which he was reclining was a Bilva tree whose leaves are highly auspicious for Shiva puja. Since he had not eaten anything the whole day, the hunter felt very hungry and could not sleep. To kill the night of the night, the hunter plucked the tree leaves and dropped them down one after another. Drops of water were dripping down from the pitcher he had carried up.
The hunter had little known that it was Shivaratri. The leaves dropped by the hunter were falling on a Siva ling found below the tree while the water dripping from his pitcher was bathing the idol. Though done unknowingly, these acts equalled giving a holy bath and puja to the idol, which conferred the great blessings of Shiva on the hunter.
Later, when he died, the messengers of Yamraj tied him in the loop and took him to Yamlok, where Shivaji’s Ganas fought with Yamdoot and freed him from the loop. In this way, Nishad joined the beloved Ganas of Lord Shiva.
Upon his death years later, the hunter was led to the abode of Shiva, where he spent some time in happiness and divine company. In his next birth, he was born as King Chitrabhanu in the Ikshvaku dynasty. Due to the merits he earned, he remembered his past birth and therefore continued observing Shivaratri Vrat throughout his life.
So, it is believed that who so ever observes fast and performs Shivaratri vrat on an auspicious day will be blessed with mental peace, prosperity, health, and happiness by Lord Shiva.