Sigiriya may have been inhabited through prehistoric times. It was used as a rock-shelter mountainmonastery from about the 5th century BC, with caves prepared and donated by devotees to the Buddhist Sangha. The garden and palace were built by King Kasyapa. Following King Kasyapa's death, it was again a monastery complex up to about the 14th century, after which it was abandoned. . The Sigiri inscriptions were deciphered by the archaeologist Senarath Paranavithanain his renowned two-volume work, published by Oxford, Sigiri Graffiti. He also wrote the popular book "Story of Sigiriya".
The Mahavamsa, the ancient historical record of Sri Lanka, describes King Kasyapa as the son of King Dhatusena. Kasyapa murdered his father by walling him alive and then usurping the throne which rightfully belonged to his brother Mogallana, Dhatusena's son by the true queen. Mogallana fled to India to escape being assassinated by Kasyapa but vowed revenge. In India he raised an army with the intention of returning and retaking the throne of Sri Lanka which he considered was rightfully his. Knowing the inevitable return of Mogallana, Kasyapa is said to have built his palace on the summit of Sigiriya as a fortress and pleasure palace. Mogallana finally arrived and declared war. During the battle Kasyapa's armies abandoned him and he committed suicide by falling on his sword. Chronicles and lore say that the battle-elephant on which Kasyapa was mounted changed course to take a strategic advantage, but the army misinterpreted the movement as the King having opted to retreat, prompting the army to abandon the king altogether. Moggallana returned the capital to Anuradapura, converting Sigiriya into a monastery complex.
Alternative stories have the primary builder of Sigiriya as King Dhatusena, with Kasyapa finishing the work in honour of his father. Still other stories have Kasyapa as a playboy king, with Sigiriya a pleasure palace. Even Kasyapa's eventual fate is mutable. In some versions he is assassinated by poison administered by a concubine. In others he cuts his own throat when isolated in his final battle. Still further interpretations have the site as the work of a Buddhist community, with no military function at all. This site may have been important in the competition between the Mahayana and Theravada Buddhist traditions in ancient Sri Lanka.