Service to the Tang Dynasty
A Tang official named Duan Wenchu was hated by the subordinate officials serving under him. Those officials asked Li for aid, and he responded by bringing more than ten thousand soldiers, defeating and killing Duan. The Tang Dynasty responded by sending armies against Li.
However, from the 870s, China’s Tang Dynasty was racked by numerous rebellions. Among the most serious was one led by Huang Chao, who sacked Chang'an in 880. The Tang emperor Xizong asked Li Keyong for assistance and granted him amnesty. Realizing this as an opportunity to expand Shatuo power into central China, Li Keyong sent the Likejun, a 40,000-strong cavalry force, to attack the Huang camp at Tongzhou. Li categorically defeated 150,000 rebels at the Battle of Liangtianpo in 882 and drove Huang Chao out of Chang'an. In February 884, his troops crossed the Yellow River and destroyed the rebel army at Battle of Zhongmou. Rebel commanders Shang Rang and Ge Congzhou both surrendered to the Tang Dynasty. Li's Shatuo cavalrymen played crucial roles in suppressing the rebellion and forcing Huang Chao to commit suicide in Langhu Valley in 884, helping Zhu Wen to quell the rebellion. For his assistance to the Tang, the emperor granted Li a base in , and was later named the Prince of Jin in 895.
Zhu Wen was displeased by the rewards granted to Li. Zhu failed in his attempt to have Li killed, and the two former comrades became heated rivals from that point.
Relations with the Later Liang Dynasty
After the fall of the Tang Dynasty in 907, Zhu Wen founded the Later Liang Dynasty. While the Later Liang dominated most of northern China, Li Keyong and the Shatuo Turks maintained a stronghold in . Called the State of Jin, they maintained their independence from the Later Liang Dynasty to the south and east. Li referred to himself as the King of Jin. He died the following year. His son continued to expand the State of Jin, and managed to overthrow the Later Liang Dynasty in 923 to form the Later Tang Dynasty.