The Tang dynasty took over China in the 7th century, and in a century they
strengthened China's armies and economy, and expanded their borders after
successful military campaigns.
But in the middle of the 8th century they began to suffer numerous defeats.
They failed to subdue the Kingdom of Nanzhou in Yunnan,
were prevented from taking Tibet,
and famously lost the Battle of Talas against the Muslims in Central Asia in 751.
All of these were incredibly costly failures and the state was running out of money.
But the 8th century was a turbulent time for many states along the SIlk Road.
In modern-day Uzbekistan the Abbasids launched a rebellion against the Umayyads,
and the large Turkic Khaganate collapsed when the Uyghurs and the Perisan Sogdians
in Central Asia rose up and later established the Uyghur Khaganate in the 740's.
This turmoil encouraged many people to enter China, including
one man, An Lushan, who was probably a Sogdian.
An Lushan entered the army and in the 730's disobeyed orders and launched an
unsuccessful campaign against the Khitans on the northern borders.
Despite his failure, this helped him rise through the ranks and became a favorite
of the Xuanzong Emperor and Chancellor Li Linfu.
He was placed in control of an army of over 100,000 men in the north near modern-day Beijing,
but began to create powerful rivals.
For instance, another general Geshu Han, who defended the borders in the west, fell out with An Lushan,
and Chancellor Li died in the 750's and the new Chancellor Yang Gouzhong
entered into a political alliance with Geshu Han.
They were fearful of An Lushan's aspirations, and the emperor found out that
An Lushan has bribed officials sent to monitor him and report on his behavior.
So, fearing his position was now under threat, An Lushan took advantage of the
popular discontent against the Tang dynasty and rebelled in 755.
His armies quickly marched south, taking modern-day Beijing and then moved along the Grand Canal
and captured Luoyang, the Eastern Capital.
Once there, he crowned himself emperor of the new Yan dynasty.
However, he continued advancing hoping to take the Western Capital Chang'an, modern-day Xi'an.
On route, the size of his armies increased a great deal because he welcomed surrendering soldiers into his ranks.
However, his advance was halted at the Battle of Yongqiu in ealry 756.
An Lushan's forces were then unable to advance because the Tang forces
were in defensive positions on the Tong Pass.
But Yang Guozhong pressured Geshu Han to meet An Lushan in battle at the end of the year.
This was a disaster and the victorious An Lushan
marched on Chang'an, forcing the emperor to flee.
An Lushan was able to capture Chang'an later that year,
killing hundreds of thousands in the process,
just as Emperor Xuanzong's son was proclaimed the Suzong Emperor.
The Suzong Emperor quickly recruited mercenaries from Mongolia and Central Asia,
and they helped fend An Lushan from advancing any further south.
It was therefore a stalemate until 757.
But An Lushan's health began to deteriorate and was killed by his own son.
His son, An Qingxu took over the Yan dynasty and tried to break the stalemate by
laying siege to Suiyang.
This was a siege that went on for months and forced the inhabitants to resort to cannibalism.
The city fell when only 400 defenders remained,
but this was an incredibly costly siege for the Yan as well.
So the Tang dynasty and the foreign mercenaries were able to reclaim Chang'an and Luoyang.
Although the Yan dynasty survived, they began to fall apart after a series of political killings.
The Yan general who failed to defend Luoyang, Shi Siming, temporarily defected but returned
to kill An Qingxu, and made himself emperor.
He was able to reclaim Luoyang, but in 761 he was killed by his own son Shi Chaoyi.
But by this point though, Shi Chaoyi didn't have the support of his generals and his armies were disjointed.
However, the Tang dynasty also faced problems.
Thousands of Persian and Arab merchants were massacured in Canton,
and the Suzong Emperor, who was sick, abdicated in 762, and the Daizong Emperor took over the Tang dynasty.
He, however, also had to fight the Tibetans who were using this opportunity to reclaim lost provinces
and would eventually take Chang'an in 763.
The Daizong Emperor increased the size of his armies by accepting help from the defecting Yan generals,
and launched an assult on the disjointed rebels.
By 763, he captured Luoyang and Shi Chaoyi committed suicide, ending the war.
The war was devastating for many provinces and some historians have estimated
tens of millions died, but this is disputed.
Although the weakened Tang dynasty reclaimed Chang'an from the Tibetans,
within a few years they lost control of the western passes into Central Asia.
And within a century the dynasty collapsed and China was thrown into a period of chaos
known as the FIve Dynasties and Ten Kingdoms Period.