Building work on the Yonghegong Temple started in 1694 during the Qing Dynasty. It originally served as an official residence for court eunuchs. It was then converted into the court of the Prince Yong (Yin Zhen), a son of the Kangxi Emperor and himself the future Yongzheng Emperor. After Yongzheng's ascension to the throne in 1722, half of the building was converted into a lamasery, a monastery for monks of Tibetan Buddhism. The other half remained an imperial palace.
After Yongzheng's death in 1735, his coffin was placed in the temple. The Qianlong Emperor, Yongzheng's successor, gave the temple imperial status signified by having its turquoise tiles replaced with yellow tiles which were reserved for the emperor. Subsequently, the monastery became a residence for large numbers of Tibetan Buddhist monks from Mongolia and Tibet, and so the Yonghe Lamasery became the national centre of Lama administration.
The temple is said to have survived the Cultural Revolution due to the intervention of Prime Minister Zhou Enlai. It was reopened to the public in 1981.