Long ago there was a sage by name Kashyapa who was married to Diti. Their son Vajranga married Varaangi who gave birth to rakshasa Taraka. Taraka performed severe penance to please Brahma, the Creator, and obtained two boons from Him. The first boon was that there should be no one more powerful than himself. The second boon was that his death could come only from a son born to Shiva.
Taraka was very bold and confident because Shiva was already deeply lost in penance and had no wife. So no son could be born. Taraka was ruthless and wicked and hated sacrifices and charity. He killed all kings who ruled over their subjects righteously.He destroyed the hermitages of the sages and set fire to the homes of good men. He put to death all pious people.
The following text has been partially borrowed from http://www.templenet.com/
Legend has it that Amaravati was once the abode of the Gods - the Devas, the yakshas and the kinnaras. They sent Brihaspati to Kusumapura to fetch Manmatha. Manmatha along with his consort Ratidevi arrived where Shiva was doing the penance. They cast their spell on Shiva and he married Parvati.Shiva's son Subramanya vanquished the demon.
The Shivalingam in his throat broke and fell in five different spots, which became the Pancharama kshetras. The foremost of these is Amareswara at Amaravati where Indra and the Devas are believed to have worshipped Shiva.
It is believed that the Shivalingam that shattered into five pieces was a huge one, and the biggest of the five pieces is a fifteen foot long column of white marble which is worshipped as Amareswara at the Amaravati temple. Legend has it that it was installed by Indra the king of the Devas, Brihaspati the guru of the Devas and Sukra the preceptor of the Asuras.
Amaravati temple is located on a small hillock referred to as Krouncha Shaila, alongside the river Krishna which flows for a short distance in a North-Southerly direction, although for the most part, the river heads eastwards towards the ocean. The river Krishna is held in reverence at this pilgrimage site, and a ritual dip in this river here is considered to be meritorious.
The structural foundations as seen today, seem to date back to the 11th century CE. The Vijayanagar kings provided grants to maintain the temple. However it was the local kings of the 18th century CE that provided vast endowments to this temple. The temple is decorated with four lofty gopurams in its outer circumambulatory path. Shiva here is referred to as Amareswara, Agasteswara, Kosaleswara, Pranaveswara, Someswara and Parthiveswara and Parvati - Bala Chamundi.
Yet another legend has it that when Shiva destroyed the three Tripuras (Tripura Samharam), all that was left was a Shivalingam, and that he divided it into five pieces and placed them for worship at the Pancharama shrines.
Yet another legend links the pancharama kshetras. The five Shivalingams worshipped at these shrines are said to be a part of a single Shivalingam said to have been created by Surya or the Sun God.
Earlier known as Dhanyakataka, Amaravathi got its present name after Amareswara Swamy