Angkor Wat lies 5.5 kilometres (3.4 mi) north of the modern town of Siem Reap, and a short distance south and slightly east of the previous capital, which was centred at Baphuon. In an area of Cambodia where there is an important group of ancient structures, it is the southernmost of Angkor's main sites.
According to legend, the construction of Angkor Wat was ordered by Indra to act as a palace for his son Precha Ket Mealea. According to the 13th century Chinese traveler Daguan Zhou, it was believed by some that the temple was constructed in a single night by a divine architect.
The initial design and construction of the temple took place in the first half of the 12th century, during the reign of Suryavarman II (ruled 1113 – c. 1150). Dedicated to Vishnu, it was built as the king's state temple and capital city. As neither the foundation stela nor any contemporary inscriptions referring to the temple have been found, its original name is unknown, but it may have been known as "Varah Vishnu-lok" after the presiding deity. Work seems to have ended shortly after the king's death, leaving some of the bas-relief decoration unfinished. In 1177, approximately 27 years after the death of Suryavarman II, Angkor was sacked by the Chams, the traditional enemies of the Khmer. Thereafter the empire was restored by a new king, Jayavarman VII, who established a new capital and state temple (Angkor Thom and the Bayon respectively) a few kilometers to the north.
Toward the end of the 12th century, Angkor Wat gradually transformed from a Hindu center of worship to Buddhism, which continues to the present day. Angkor Wat is unusual among the Angkor temples in that although it was somewhat neglected after the 16th century it was never completely abandoned, its preservation being due in part to the fact that its moat also provided some protection from encroachment by the jungle.