An Lushan
Between 630 and 730, the Khitans were under the influence of the Tang dynasty through the Dahe clan. The Tang emperor bestowed the Chinese surname Li on the Dahe and appointed their leader to a governorship that was "an office specifically created for the indirect management of the Khitan tribes". Towards the turn of the century, however, Tang control of the north began to slip . In 696 the Dahe leader, Li Jinzhong, launched a rebellion and led Khitan forces into modern Hebei. Although the rebellion was defeated, it took over fifteen years before the Tang were able to reassert control over the Khitans, and that control would never be strong or long-lived. In the 730s, the Yaonian clan replace the Dahe as the Khitan's ruling clan, forcing Tang governor An Lushan to launch two invasions into Khitan territory in 751 and 755. After being soundly defeated by the Khitans during the first invasion, An Lushan was successful in the second, but he then led a rebellion against the Tang that included Khitan troops in his army. An Lushan had a Khitan eunuch named Li Zhuer who worked for him as a teenager but An Lushan used a sword to sever his genitals and he almost died after losing multiple pints of blood. An Lushan revived him by smearing ashes on his injury. Li Zhuer was highly trushed by An Lushan, and he and two other men served as his personal attendants. Li Zhuer was approached by conspirators who wanted to kill An Lushan when he became ill and started abusing his subordinates. An Lushan was hacked to death by Li Zhuer and another conspirator, Yan Zhuang, who was beaten by An before. An Lushan screamed "this is a thief of my own household" as he desperately shook his curtains since he could not find his sword to defend himself. The An Lushan Rebellion marked the beginning of the end of the Tang dynasty.