A temple was first built at the site around 850 CE by Rakai Pikatan and expanded extensively by King Lokapala and Balitung Maha Sambu the Sanjaya king of the Mataram Kingdom. According to the Shivagrha inscription of 856 CE, the temple was built to honor Lord Shiva and its original name was Shiva-grha (the House of Shiva) or Shiva-laya (the Realm of Shiva). According to Shivagrha inscription, a public water project to change the course of a river near Shivagrha Temple was conducted during the construction of the temple. It is therefore slightly later but more or less contemporaneous with Borobudur. In the 10th century the temple was largely abandoned after the Mataram dynasty moved its court base to East Java.

The Javanese locals in the surrounding villages knew about the temple ruins before formal rediscovery, but they did not know about its historical background: which kingdoms ruled or which king commissioned the construction of the monuments. As a result, the locals developed tales and legends to explain the origin of temples, infused with myths of giants, and a cursed princess. They gave Prambanan and Sewu a wondorous origin; these were said in the Loro Jonggrang legend to have been created by a multitude of demons under the order of Bandung Bondowoso.