Tang-Nanzhao conflicts in Annan

Tang–Nanzhao conflicts in Annan was a period of and warfare in Annan (present-day northern Vietnam) between local rebel forces, Nanzhao, and the Tang dynasty that lasted from 854 to 866. It ended in the defeat of Nanzhao and the retaking of Annan by the Tang general, Gao Pian, although the region would later become semi-independent from the Tang dynasty in 880.

Prelude (854–857)
Nanzhao was a powerful kingdom to the southwest of the Tang dynasty. Nanzhao expanded their empire in every direction, defeating a Tang invasion in 751, joining with the Tang and defeating the Tibetans in 801, decimating the Pyu city-states in 832, and subduing the Michen kingdom (near Ayeyarwady River) in the 830s. Nanzhao first raided the Tang frontier province of Annan in 846. Nanzhao then offered peace to the Tang, but in 854 the Tang suspended relations with Nanzhao and refused to receive its tribute.

The Annan Protectorate (now northern Vietnam), with its capital city of Songping, was a center of commerce on the Maritime Silk Road and a rice basket of the Tang empire at the time. When Li Zhuo became jiedushi of Annan in 854, he reduced the amount of salt traded to the Chongmo Man in Fengzhou (modern-day Phú Thọ and Hòa Bình Province) in the west in exchange for horses. The mountains chiefs responded by launching raids on Tang garrisons. When Li Zhuo began suffering defeats, Đỗ Tồn Thành, a military commander, allied himself with the tribal chiefs against Li. In the next year, Li Zhuo killed Đỗ Tồn Thành as well as the chieftain of the Qidong Man in Aizhou (Nghệ An, central Vietnam). The Đỗ tribe had been a powerful Viet family in Thanh Hoá and Nghệ An since the 5–6th century. These actions provoked the natives into an alliance with Nanzhao. Fan Chuo, a Tang official in Annan reported: "…The native chiefs within the frontiers were subsequently seduced by the Man rebels…" and "again became close friends with them. As days passed and months came, we gradually had to encounter raids and sudden attacks. This caused a number of places to fall into rebel hands."

Early phase (857–862)
In modern-day Phú Thọ and Hòa Bình Province on the western frontier of the protectorate, the local general Lý Do Độc who led an army of 6,000 and was assisted by seven commanders called "Lords of the Ravines", submitted to Nanzhao. The Nanzhao king Meng Shilong (蒙世隆) sent a Trustee of the East to deliver a letter to Do Độc soliciting his submission. Lý Do Độc and the Lords of the Ravine accepted the offer of vassalage by the Nanzhao king, who sent the Trustee one of his daughters to marry Lý Do Độc's eldest son. In 858, Nanzhao dispatched military forces to the region. In the meantime, local chiefs led raids that brought warfare to villages in the heart of the protectorate.

In 857, Song Ya was sent to Annan to deal with the situation, but was recalled to deal with another rebellion after only two months. His replacement, Li Hongfu, only had nominal control over the protectorate, which was actually controlled by La Hanh Cung, who commanded 2,000 well trained soldiers. By 858, the Nanzhao army had joined with Lý Do Độc's force and raided Annan's capital Songping. In 858, the Tang court sent a new jiedushi, Wang Shi, to protect Annan. He banished La Hanh Cung, saw off a Nanzhao reconnaissance force, and defeated an invasion by the mountain tribes. The Tang garrisons were upgraded with heavy-armored cavalry and infantry and Songping was fortified with a reed palisade. In the same year, a serious rebellion broke out in Yongzhou. The situation in Yongzhou threatened land communication between Annan and the empire, so a special army was established there to deal with rebels and to insure communications. This army was called the Yellow Head Army, for the soldiers wore yellow bands around their heads. In early autumn, local people were agitated by a rumor that the Yellow Head Army had embarked to attack them by surprise. One evening they surrounded Songping and demanded that Wang Shi return north and allow them to fortify the city against the Yellow Head Army. Shi was eating his evening meal when this commotion broke out. It is reported that, paying no heed to the mutineers, he leisurely finished his meal. Then, dressed in his battle gear, he appeared on the wall with his generals and admonished the crowd of rebels, who dispersed. The next morning, Shi's troops captured and beheaded some ringleaders of the affair.

In 860, Wang Shi was recalled to deal with a rebellion elsewhere. The new jiedushi, Li Hu, arrived at Songping and executed Đỗ Tồn Thành's son, Đỗ Thủ Trừng, who according to Chinese sources was involved in a mutiny years earlier, probably due to the death of his father at the hands of Li Zhuo four years earlier. This alienated many of the powerful local clans of Annan. Anti-Tang Viets allied with highland people, who appealed to Nanzhao for help, and as a result invaded the area in 860, briefly taking Songping before being driven out by a Tang army the next year. Prior to Li Hu's arrival, Nanzhao had already seized Bozhou. When Li Hu led an army to retake Bozhou, the Đỗ family gathered 30,000 men, including contingents from Nanzhao to attack the Tang. When Li Hu returned, he learned that Annan had been lost to Đỗ. On 17 January 861, Songping fell and Li Hu fled to Yongzhou. Li Hu retook Songping on 21 July but Nanzhao's forces moved around and seized Yongzhou. Li Hu was banished to Hainan island and was replaced by Wang Kuan. Wang Kuan and the Tang court sought local cooperation by recognizing the power of the Đỗ family, granting a posthumous title to Đỗ Tồn Thành along with an apology for the deaths of him and his son and an admission that Li Hu had exceeded his authority.

A relief army of 30,000 men was sent to Songping but soon left the city when rivalry broke out between Cai Xi, the military governor, and Cai Jing, an administrative and military official of Lingnan. Cai Xi was then left responsible for holding Songping against an imminent Nanzhao offensive. The city was surrounded by 4 miles (6,344 meters) of moated rampart–some parts seven to eight meters high. East of the city was the Red River. Much of the information about the battle was written by Fan Chuo, a Tang official who wrote an eyewitness account about the southern barbarians (people of Annan and Yunnan) during the siege.

Nanzhao offensive (863)
In mid-January of 863, Nanzhao returned with an invasion force numbering 50,000 led by Duan Qiuqian and Yang Sijin and besieged Annan's capital Songping. Nanzhao's army included an assortment of Man tribes. There were 5–6,000 local Taohua forces, 2–3,000 Mang Man from west of the Mekong River who wore blue trousers and canes and strips of bamboo on their waists, Luoxing Man who wore no clothes except tree bark, He Man from the borderlands, Xunjuan Man who went barefoot but could tread on brambles and thorns and wore wicker helmets, and Wangjuzi Man whose menfolk and womenfolk alike were nimble and good with the lance on horseback.

On 20 January, the defenders led by Cai Xi killed a hundred of the besiegers. Five days later, Cai Xi captured, tortured, and killed a group of enemies known as the Puzi Man. A local official named Liang Ke (V. Lương Cảo, belonged to the Puzi tribe) who was related to them recognized their dead bodies by their distinctive helmets and belts unique to each tribe, and defected. The troops of the Jiangxi General took the corpses of the besiegers and broiled them. He defected.

On 28 January, a naked Buddhist monk, possibly Indian, was wounded in the breast by an arrow shot by Cai Xi while strutting to and fro outside the southern walls. He was carried back to the camp by lots of Man. On 14 February, Cai Xi shot down 200 of the Wangjuzi and over 30 horses using a mounted crossbow from the walls. By 28 February, most of Cai Xi's followers had perished, and he himself had been wounded several times by arrows and stones. The enemy commander, Yang Sijin, penetrated the inner city. Cai Xi tried to escape by boat, but it capsized midstream, drowning him. Fan Chuo escaped east via the Red River. The 400 remaining defenders wanted to flee as well, but could not find any boats, so they chose to make a last stand at the eastern gate. Ambushing a group of enemy cavalry, they killed over 2,000 enemy troops and 300 horses before Yang sent reinforcements from the inner city.

After taking Songping, on 20 June Nanzhao laid siege to Junzhou (modern Haiphong). A Nanzhao and rebel fleet of 4,000 men led by a chieftain named Chu Đạo Cổ (Zhu Daogu, 朱道古) was attacked by a local commander, who rammed their vessels and sank 30 boats, drowning them. In total, the invasion destroyed Tang armies in Annan numbering over 150,000. Although initially welcomed by the local Vietnamese in ousting Tang control, Nanzhao turned on them, ravaging the local population and countryside. Both Chinese and Vietnamese sources note that the Viets fled to the mountains to avoid destruction. A government-in-exile for the protectorate was established in Haimen (near modern-day Hạ Long) with Song Rong in charge. Ten thousand soldiers from Shandong and all other armies of the empire were called and concentrated at Halong Bay for reconquering Annan. A supply fleet of 1,000 ships from Fujian was organized.

Tang counterattack (864–866)
The Tang launched a counterattack in 864 under Gao Pian, a general who had made his reputation fighting the Türks and the Tanguts in the north. In September 865, Gao's 5,000 troops surprised a Nanzhao army of 50,000 while they were collecting rice from the villages and routed them. Gao captured large quantities of rice, which he used to feed his army. A jealous governor, Li Weizhou, accused Gao of stalling to meet the enemy, and reported him to the throne. The court sent another general named Wang Yanqian to replace Gao. In the meantime, Gao had been reinforced by 7,000 men who arrived overland under the command of Wei Zhongzai. In early 866, Gao's 12,000 men defeated a fresh Nanzhao army and chased them back to the mountains. He then laid siege to Songping but had to leave command due to the arrival of Li Weizhou and Wang Yanqian. He was later reinstated after sending his aid, Zeng Gun, to the capital and he returned with a reinstatement. Gao completed the retaking of Annan in fall 866, executing the enemy general, Duan Qiuqian, and beheading 30,000 of his men.

Aftermath
Gao Pian rebuilt the capital citadel, repairing 5,000 meters of damaged wall, reconstructing 400,000 bays for its residents, and named it Đại La. He also renamed Annan to Jinghai Jun (Tĩnh Hải quân, lit. Peaceful Sea Army). More than half of local rebels fled into the mountains at this time. This may well have sealed the separation of Muong from Vietnamese, which historians such as Henri Maspero suggest based on linguistic evidence took place at the end of Tang rule in Annan.

A campaign against local population in Annan was conducted from 874 to 879. In 877, troops deployed from Annan in Guangxi mutined. In 880, the army in Annan mutinied, took the city of Đại La, and forced the military commissioner Zeng Gun to flee, ending de facto Chinese control in Vietnam.