The temple was originally Yamashina-dera Temple which was founded by Kagami no Okimi, the wife of Fujiwara no Kamatari (614-669), who was the founder of the Fujiwara clan, in Yamashina (Yamashina Ward, Kyoto City), Yamashiro Province in 669; at Kamatari's behest it has Shaka Sanzon statues (statues of the Shakyamuni triad) as its principal image, and was established in order to pray for cure of a disease he suffered from.
藤原氏の祖である藤原鎌足（614年-669年）夫人の鏡王女（かがみのおおきみ）が夫の病気平癒を願い、鎌足発願の釈迦三尊像を本尊として、天智天皇8年（669年）山背国（山城国）山階（京都市山科区）に創建した山階寺（やましなでら）が当寺の起源である。