Tripurasura

Tripurasura (Sanskrit: त्रिपुरासुर) is a trio of asura brothers named Tarakaksha, Vidyunmāli and Kamalaksha, who were the sons of the asura Tarakasura. These three began to perform severe tapasya. They were then granted boons by Brahma to have three forts: gold, silver, and iron, which angered the Devas. Vishnu then made a new religion to make them evil, and the objective of killing the asuras was taken upon by Lord Shiva, which took three days on the battlefield, finally killing Tripurasura and destroying the three cities. This occurred on the full moon day in the Kartik month and therefore the day is celebrated as Tripurari Pournima.

The Legend of Tripurasuras , is first mentioned in Taittirīya Samhita of the Krishna Yajurveda -

The Asuras had three citadels; the lowest was of iron, then there was one of silver, then one of gold. The gods could not conquer them; they sought to conquer them by siege; therefore they say--both those who know thus and those who do not--'By siege they conquer great citadels.' They made ready an arrow, Agni as the point, Soma as the socket, Visnu as the shaft. They said, 'Who shall shoot it?' 'Rudra', they said, 'Rudra is fierce, let him shoot it.' He said, 'Let me choose a boon; let me be overlord of Pashus.' Therefore is Rudra overlord of Pashus. Rudra let it go; it cleft the Citadels and drove the Asuras away from these worlds.
-Krishna Yajurveda, Taittirīya Samhita, 6.2.3 .

This legend is later told in the Itihāsas and Purānas with more detail.

The legend with more detail in the Purānas and Itihāsas-

The three brothers began to perform tapasya. For a hundred years they meditated standing only on one leg. For a thousand more years they lived on air and meditated. They stood on their heads and meditated in this posture for yet another thousand years. Brahma was pleased with this difficult tapasya. He appeared before them and said, "What boon do you want?" "Make us immortal", answered Tarakasura's sons. "I can’t make you immortal", replied Brahma. "I don’t have the power. Ask for something else instead". "Very well", then, said Tarakaksha, Vidyunmāli and Kamalaksha. "Grant us the following: Let three forts be made. The first will be of gold, the second of silver and the third of iron. We will live in these forts for a thousand years. These forts built in different worlds shall align once in every 1000 years. This combined fort will be called Tripura. And if anyone can then destroy Tripura with only a single arrow that shall be the death destined for us".

This rather unusual boon Brahma granted. There was a Danava named Maya who was very good at building work. Brahma asked him to build the forts. The golden fort was built in heaven, the silver one in the sky and the iron one on earth. Tarakaksha got the golden fort, Kamalaksha the silver one and Vidyunmali the iron one. Each of the forts was as big as a city and had many palaces and vimanas inside.

The asuras populated the three forts and began to flourish. The gods did not like this at all. They first went to Brahma, but Brahma said he could not help them. After all, the asuras had got Tripura thanks to his boon. The gods then went to Shiva for help. But Shiva said that the asuras were doing nothing wrong. As long as that was the case, he did not see why the gods were so bothered. They next went to Vishnu, who suggested that if the problem was that the asuras were doing nothing wrong, then the solution was to persuade them to become sinners.

Out of his powers Vishnu created a man. This man's head was shaven, his clothes were faded and he carried a wooden water-pot in his hands. He approached Vishnu. "What are my orders?" he asked Vishnu.

"Let me explain to you why you have been created", replied  Lord Vishnu. "I will teach you a religion that is completely against the Vedas. You will then get the impression that there is no Svarga (heaven) and no Naraka (hell) and that both heaven and hell are on earth. You will not believe that rewards and punishments for deeds committed on earth are meted out after death. Go to Tripura and teach the demons this religion, by which they will be dislodged from the righteous path. Then we will do something about Tripura".

The being did as he had been asked to. He and four of his disciples went to a forest that was near Tripura and began to preach. They were trained by Vishnu himself. Therefore, their teachings were convincing and they had many converts. Even the sage Narada got confused and was converted. In fact, it was Narada who carried news of this wonderful new religion to King Vidyunmali. "King" he said, "there is a wonderful new teacher with a wonderful new religion. I have never heard before. I have been converted."

Since the great sage Narada had been converted, Vidyunmali also accepted the new religion, and in due course, so did Tarakaksha and Kamalaksha. The asuras gave up revering the Vedas, they stopped worshipping Shiva linga.

Now the gods then went to Shiva and began to pray to him. When Shiva appeared, they told him that the asuras had now become evil and should be destroyed. They had even stopped worshipping Shiva's linga.

Shiva agreed to destroy Tripura. Vishvakarma was the architect of the gods. Shiva called Vishvakarma and asked him to make a suitable chariot, bow and arrow. The chariot was made entirely out of gold. Brahma himself became the charioteer and the chariot was speedily driven towards Tripura. The gods accompanied Shiva with diverse weapons.

When Shiva's army reached the battlefield, the three forts were about to merge into a single Tripura, which condition would last for just a second. At the exact time, Lord Shiva invoked the most destructive weapon controlled by Him, the Pashupatastra. The Destroyer's capable arms fired a single arrow into the three forts at the exact instant they merged into one, thus burning to ashes the three forts of the asuras. Shiva thus earned Himself the epithet Tripurantaka - the one who ended Tripura, and Paśupatinath - wielder of the Pashupatastra. He also earned the epithet Tripurari.

Another version that is widely quoted in Tamil literature has Lord Shiva destroying Tripura with a mere smile. When all the battlefield was filled with warriors, with Brahma and Vishnu in attendance, there occurred the instant when the forts came together. Lord Shiva merely smiled. The forts were burned to ashes. The battle was over before it began! In Tamil, Lord Shiva has the epithet, "Sirithu Purameritha Peruman" which means, He who burnt the cities with a mere smile.

While the celebrations were going on, the shaven-headed religious teachers arrived. "What are we supposed to do now?" they asked.

Brahma and Vishnu told them to go the desert where there are no humans. The last of the four eras was Kali Yuga and in Kali Yuga, evil would reign supreme. When Kali Yuga arrived, they were to come back and begin their teaching afresh. And once they reached at their peak god will take rebirth and will wipe them from earth and once again the world will be free from all kinds of evil and asuras.

See also
Adharma
Atheism
Nastika
Mleccha

References 
A Concise Encyclopedia of Hinduism (Klaus K. Klostermaier)   Publisher, Oxford (One World Publications)

A Tripurasura's Past Life: http://www.harekrsna.com/philosophy/associates/demons/siva/tarakasura.htm

Asura