Demon Taraka had 3 children namely, Tarakaksha, Kamalalochana, and Vidyunmaali. The three together performed deep penance and Brahma pleased with their devotion appeared before them. They asked a boon to be immortalized to which Brahma said that he did not possess the power to grant this boon. They then asked for a boon wherein they wanted 3 cities to be built like a fortress and the Devas and other citizens should serve them in these forts. Brahma granted the boon, but said that when someone hits the 3 cities with a single arrow then that will be the end of the three cities. Brahma thus disappeared with the blessing that the three of them live a thousand years. The demons thought that the probability of the three cities aligning could be once in 1000 years and rejoiced that they got what they wanted.
The above picture is from Nanjanagudu
The Demon architect Maya was summoned to build the three cities. Maya built a city in Patala (nether world) using iron, one on earth using silver, and one on heaven using gold. The three demons were very proud and happy of the cities built in different paths and filled their wells with the Amrutha (nectar) from heaven and made all the devas (gods and goddesses) and the apsaras (dancers) their maids and servants.
The pained devas (gods and goddesses), sages, saints, monks, along with the king of Devas Indra secretly met and discussed the situation. Indra decides to meet Brahma who gave the boon to Tarakaksha, Kamalalochana, and Vidyunmaali. Indra consults Brahma to show a way to end this torture.
Brahma with the others decide to go to and meet Lord Shiva in Kailasa. Brahma, Devas, and the rest pay their respects to Lord Shiva and confide in him their troubles.
Lord Shiva says that he would never let his people down, and assures them that with the Pashupathasthra he will be able to burn the three cities. But, he says that he will be able to take this action only if the asuras (demons) have sinned.
Lord Vishnu in the form of a cow along with Brahma in the form of a calf, dive into the wells of the three cities and drink up the Amrutha (nectar) that the three demons had filled them with. In order to make the Asuras sin, Lord Vishnu creates a man whose head is shaven, his clothes are faded and he carries a wooden water-pot in his hands. This avatar of Vishnu is known as Bhauddavataara (note: not Gautama Buddha). Bhaudda preached Shoonyaveda to the asuras and did it in such a way that the Asuras started following this veda and shunned the puranic vedas. As the respective wives of the asuras were pathi vrata (a woman who is sincere towards her husband), Bhaudda walked naked in front of the wives and when they looked at him, their pathi vrata got destroyed. Now, the asuras had sinned and could be killed when the three cities align.
Immediately, the Devas asked Vishwakarma to create a chariot. The earth became the carriage, the 4 Vedas became the horses, the sun and moon became the wheels, and Lord Brahma became the charioteer (sarathi). Lord Shiva bound his jate (jataa/matted hair) with King Cobra, wore the skin of the Elephant and taking the Pashupathasthra he marched along with his Bhoothagana (ghosts and other beings), and his vehicle Nandi and climbed up the chariot. A loud cheer (jai jai kar) went up the air.
Lord Shiva using his powers fast forwarded the time to 1000 years and the three cities aligned. Lord Shiva used Vasuki (king of snakes) as the bow string, and mount Meru as his bow and using the Pashupathastra (arrow) destroyed the three cities and the asuras (demons) to ashes.
All the people were relieved and sang praises of Lord Shiva and life returned back to normal.
Har har Mahadev!
Note: This is as written in Kumaravyasa Mahabharatha.