Story of Rahu and Shiva is found in the Skanda Purana. Legend has it that once demon chief Jalandhara asked Rahu to carry a message to Shiva. The chief asked Rahu to inform Shiva that he was an incapable husband, as he could not appease Goddess Parvati as he roamed the cremation grounds. So Goddess Parvati should be sent to Jalandhara.
When Rahu said the same before Shiva, he opened his third eye and produced a huge being.
That huge being threw Rahu into the sky. He thus became a navgraha.
This whole incident happened in a place known as Barbara and therefore Rahu is also known as Barabarodhuta.