(Although well-known, I intend to write about the ‘Churning of Ocean’ at length some other time, to explore some perspectives that I find fascinating).
By this time the churning of the ocean is complete. All precious things that were under water - including the Sun, the Moon (Soma), the celestial nymphs called Apsaras, the great horse Ucchaishravas, the goddess of wealth Laxmi, the wine Varuni and several other great and desirable things or beings – there are about 14 of them in total – have surfaced. The Sun and the Moon, being forms of light, are welcomed instantly by the gods, who themselves are forms of light (the words deva and diva for light have similar etymological roots) and are admitted to their company. The great black poison Kalakoot has also surfaced, and Shiva / Rudra has swallowed it to protect the world from it.
Do take a moment to pause and reflect how gods and demons must be so physically similar that a demon can easily pass off as a god. The demons in Hindu myths are not ugly, dark, hideous, but in fact almost undifferentiated from gods in their physical appearance. That the demons were ugly, dark and hideous is part of the now-outdated Western view of depicting the puranic battles between devas and danavas as a reflection of the Aryan-Dravidian divide - which has also colored the views of countless Indians themselves about their own stories and mythology.
So, Rahu, the Asura’s head, gets the tail of serpent; while Ketu, the headless body, gets the serpent’s head. Ketu continues to wander around the solar system aimlessly, like a comet. Indeed, the name for comet in some of the Indian languages is ‘Dhoom ketu’ – Ketu with smoke. Ketu typically means 'pataka' or banner, and the comet does look like a flag or a banner. Siddhartha Gautama (Buddha) is called "Dharma-ketu" in some later scriptures - the banner of dharma.
So that is the long and short of how Rahu and Ketu came to be. What is interesting is that Rahu and Ketu are considered shadow planets in Hindu astrology, and included in the nine planets (navgrahas). More about the individual planets later.