The origin is rooted in the Shiva Purana, with accounts of Shiva's marriage to Parvati, his cosmic dance, and his drinking of the poison during the churning of the ocean.
According to the Shiva Purana, on this night Shiva performed the cosmic dance (Tandava) and married Parvati. It is also the night Shiva is said to have saved the world by drinking the poison that arose from the churning of the ocean.
Shiva Purana