Established by imperial edict in 796 AD and named Kyo-o-gokoku-ji, Toji was built to guard the city. It is more commonly known as Toji (Eastern Temple) because it once had a partner, Saiji (Western Temple), and the two stood alongside the Rashomon, the gate to the Heian capital. These were the only two temples that Emperor Kammu permitted to be built in the city, for he had had enough of the powerful Buddhists during his days in Nara.
In 823, Emperor Saga gave the temple to the priest Kukai (Kobo Daishi), who founded the Shingon sect of Buddhism. To-ji became one of Kyoto's most important temples.
Fires and wars during the 16th century destroyed most of the temple buildings. One survivor is the Kodo (Lecture Hall), which has survived intact since it was built in 1491. The others were rebuilt, including the Kondo (Main Hall) in 1603.
UNESCO designated Toji a World Heritage Site in 1994.