The area is thought to be inhabited from as early as the 7th to 3rd century BC. Statues and paintings in these caves date back to the 1st century BC. But the paintings and statues were repaired and repainted in the 11th, 12th, and 18th century AD. The caves in the city provided refuge to King Valagamba (also called "Vattagamini Abhaya") in his 14-year-long exile from the Anuradhapura kingdom. Buddhist monks meditating in the caves of Dambulla at that time provided the exiled king protection from his enemies. When King Valagamba returned to the throne at Anuradapura kingdom in the 1st century BC, he had a magnificent rock temple built at Dambulla in gratitude to the monks in Dambulla.