The Fayuan Temple, originally named the Minzhong Temple, was first built in 645 during the Tang dynasty by Li Shimin (Emperor Taizong). It was later rebuilt in the Zhengtong era (1436–1449) of the Ming dynasty. Emperor Taizong founded the temple to commemorate his soldiers who died in his campaign against Goguryeo.
Fayuan Temple was originally built to mourn the dead soldiers by Emperor Taizong (598-649) of the Tang Dynasty (618-907). When finished in 696, Empress Wu Zetian (624-705) gave it the name Minzhong Temple, which means a temple to mourn the late loyal people. However, due to flood, earthquake, war and other damages, the temple has been destroyed, rebuilt, and renamed several times. It was not until the Emperor Yongzheng’s throne in the Qing Dynasty (1636-1912) that it was greatly repaired and then renamed as Fayuan Temple, which has been retained to the present day. In fact, since the temple was first built to recall the dead soldiers, there were several loyal people who were associated to it in different dynasties. During the Yuan Dynasty (1271-1368), Xie Fangde (1226-1289), official of the fallen former Southern Song Dynasty (1127-1279), starved himself to death in the temple as he would not surrender to the new rulers. In the late Qing Dynasty, after the leaders of the Reform Movement in 1898 had been killed, their coffins were stored in this temple for some time. For more than a thousand years, the temple has witnessed the change of history.