Samudra Manthana means "churning the ocean". (Samudra means "ocean" and Manthana means "churning".) The ocean in question is Kshira Sagar (ocean of milk) on which Lord Vishnu reclines on the serpent Shesha along with his consort, Goddess Lakshmi. During the Samudra Manthana, the gods and demons joined forces to churn the ocean of milk to obtain amrita (the nectar of immortality). Mount Mandara was used as the churning rod and was placed on the back of Lord Vishnu's Kurma (Tortoise) avatar. The serpent on Lord Shiva's neck, Vasuki, was used as the churning rope. The gods held the rear of the snake, and the demons held the front; this tug-of-war lasted for what seemed an eternity.
During the churning, Vasuki initially emitted poison from its mouth, which could have destroyed the entire universe. Shiva consumed the poison, and his neck turned blue. This is why Shiva is also known as Nilkantha, meaning "one with a blue neck."
As the churning continued, Kamadhenu (the wish-fulfilling cow) and a pot of wine sprang out of the ocean. The demons relished the wine. Several celestial nymphs also appeared, seemingly to distract the demons. Goddess Lakshmi emerged from the ocean, holding a lotus in her hands. For this reason, Lakshmi is considered the daughter of the ocean god. At long last, Dhanvantari, the court physician, arrived with the pot of amrita.
Just as the royal physician was about to hand the pot to the gods, the demon Svarbhanu grabbed it and fled. Terrified by the prospect of the demons gaining eternal life, the gods sought Lord Vishnu's help.
Vishnu pursued the sinister Svarbhanu, who was fleeing with the amrita pot. He then assumed his Mohini avatar, an enchantress whose beauty enthralled Svarbhanu. Mohini, offering to distribute the amrita among the gods and demons, took the pot from Svarbhanu.
Both the gods and demons laid claim to the amrita. Mohini instructed the gods to sit in one row and the demons in another. The demons foolishly allowed Mohini to serve the gods first, and thus, the gods became immortal. The cunning Svarbhanu disguised himself as a god and sat among them.
The Sun god, Surya, and the Moon god, Chandra, alerted Mohini that she had inadvertently given amrit to a demon, but it was too late—Svarbhanu had already swallowed his share and become immortal. Mohini then transformed back into Vishnu, who used his Sudarshana Chakra to behead Svarbhanu. However, even that did not kill him, as he had already gained immortality. Svarbhanu’s disembodied head lived on as Rahu, while the rest of his body became Ketu.
It was now the demons' turn to receive the amrita. However, the amrita pot was empty—Vishnu had deceived them.
After being beheaded, Svarbhanu vowed to take revenge on Surya and Chandra for exposing him. Thus, solar eclipses occur when Rahu swallows the Sun, and the eclipse ends when the Sun reemerges from his severed neck. Similarly, lunar eclipses are caused by Ketu swallowing the Moon.