Legend credits the temple’s foundation to Kukai, the teacher of Japanese esoteric Buddhism who lived at the turn of the ninth century.