Indra, while riding on an elephant, came across a sage named Durvasa who offered him a special garland. Indra accepted the garland, placing it on the trunk of the elephant. The elephant threw the garland to the ground. This enraged the sage as the garland was a symbol of fortune and was a gift. Durvasa cursed Indra and all the gods to be bereft of all strength, energy, and fortune.
In order to regain their lost immortality and other possessions, the gods went to Vishnu, who advised them to drink amrita (nectar). The only was to do this was to churn the cosmic ocean. However, they were not strong enough to do this alone, so they enlisted the help of their enemies; the Asuras, promising them half the reward. They used Mount Meru as a rod, supported by Vishnu in his form as Kurma the turtle and Vasuki, the king of serpents, as a rope. The gods pulled from the tail and the demons from the head. Thus the demons were poisoned by the fumes emitted by Vasuki. The ocean began to release a deadly poison from its depths, which was consumed by Shiva. Parvati choked Shiva to try and remove the poison from his throat. The poison did not take effect but turned Shiva blue.
After churning the ocean for a millenium, several gifts were yielded up including amrita, Airavat the elephant (Indra's mount), the Ashvins (physicians to the gods) and Jyestha, goddess of misfortune.
The asuras attempted to take their share of the amrita but Vishnu, incarnated as Mohini, tricked the asuras out of their share. Rahu, an asura, drank some nectar but Surya alerted Vishnu, who decapitated him. Thus only Rahu's head was immortal, becoming the north lunar node, whilst his body became Ketu, the south lunar node.
The devas then drank the nectar of immortality and resumed their former positions.