Note: The ocean in question is Kshirasagara (Sanskrit for "ocean of milk"), where Lord Vishnu reclines on the serpent Shesha along with his consort, Goddess Lakshmi.
The gods and the demons joined forces to churn the ocean of milk to obtain the nectar of immortality. Mount Mandara was used as the churning rod and was placed on the back of Lord Vishnu's Kurma (Sanskrit for "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 eons.
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 Nilakantha (Sanskrit for "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 nectar.
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 nectar pot. He then assumed his Mohini avatar, an enchantress whose beauty enthralled Svarbhanu. Mohini, offering to distribute the nectar among the gods and demons, took the pot from Svarbhanu.┬а
Both the gods and demons laid claim to the nectar. 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 and the Moon gods alerted Mohini to the fact that she had inadvertently given nectar 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 nectar, but the pot was emptyтАФVishnu had deceived them.
After being beheaded, Svarbhanu vowed to take revenge on the Sun god and Moon god 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.
Vishnu Puran (2000 Hindi TV series) by B.R. Chopra