Construction of the first temple on the site began in the early 9th century; both then and in the following centuries it was dedicated to the Hindu god Shiva in his manifestations as the mountain gods Sikharesvara and Bhadresvara. The earliest surviving parts of the temple, however, date from the Koh Ker period in the early 10th century, when the empire's capital was at the city of that name. Today, elements of the BanteaySrei style of the late 10th century can be seen, but most of the temple was constructed during the reigns of the Khmer kingsSuryavarman I (1002–1050) and Suryavarman II (1113–1150). An inscription found at the temple provides a detailed account of Suryavarman II studying sacred rituals, celebrating religious festivals and making gifts, including white parasols, golden bowls and elephants, to his spiritual advisor, the aged Brahmin Divakarapandita. The Brahmin himself took an interest in the temple, according to the inscription, donating to it a golden statue of a dancing Shiva known as "Nataraja". In the wake of the decline of Hinduism in the region the site was converted to use by Buddhists.
The temple complex runs 800 m (2,600 ft) along a north-south axis facing the plains to the north, from which it is now cut off by the international border. It consists essentially of a causeway and steps rising up the hill towards the sanctuary, which sits on the clifftop at the southern end of the complex (120 m/390 ft above the northern end of the complex, 525 m/1,722 ft above the Cambodian plain and 625 m/2,051 ft above sea level). Although this structure is very different from the temple mountains found at Angkor, it serves the same purpose as a stylised representation of Mount Meru, the home of the gods.
The approach to the sanctuary is punctuated by five gopuras (these are conventionally numbered from the sanctuary outwards, so gopura five is the first to be reached by visitors). Each of the gopuras before the courtyards is reached by