Lý–Song War

The Lý–Song War was a significant war fought between the Lý dynasty of Đại Việt and the Song dynasty of China between 1075 and 1077. The war began in 1075 when the Lý emperor ordered a preemptive invasion of the Song dynasty using more than 100,000 soldiers, where Đại Việt's forces defeated the Song army and razed the city of Yongzhou (modern day Nanning) to the ground after a forty-two day siege. In response, in 1076 the Song led an army of over 300,000 to invade Đại Việt and by 1077 nearly reached Thăng Long, the capital of Đại Việt, before being halted by general Lý Thường Kiệt at the Nhu Nguyệt River in modern Bắc Ninh Province. After a long battle at the river with high casualties on both sides, Lý Thường Kiệt offered peace to the Song, and the Song commander Guo Kui agreed to withdraw his troops, ending the war.

Background
Tension and border hostilities were already high in the years prior to the war; in the 1050s, Nùng Trí Cao, the head of the local Nùng people in Quảng Nguyên (now Cao Bằng Province) attempted to fight for independence and establish a frontier state for his people, but his rebellion was crushed by Song general Di Qing (1008–1061). While the Lý court did not intervene in the matter, the threat of Song expansion was always on the horizon due to increasing numbers of Han Chinese settlers, such as the soldiers from Di Qing's division and those north of the Yangzi River settled in areas that the Lý relied upon for the extraction of natural resources.

In 1075, Wang Anshi, the chancellor of the Song dynasty, told Emperor Shenzong (r. 1067–1085) that Đại Việt was being destroyed by Champa, with less than ten thousand soldiers surviving, so hence it would be a good occasion to annex Đại Việt. The Song emperor then mobilized his troops and passed a decree to forbid all the provinces of Song to trade with Đại Việt; this prompted the Lý court under Emperor Lý Nhân Tông (r. 1072–1127) to authorize a preemptive invasion of Guangxi in the Song dynasty. Lý Nhân Tông then sent general Lý Thường Kiệt and Nùng Tông Đán, a kinsman of the Nùng rebel Nùng Trí Cao, to lead more than a hundred thousand soldiers to invade the Chinese province of Guangxi.

The War
In the autumn of 1075, Nùng Tông Đán advanced into Song territory in Guangxi while a naval fleet commanded by Lý Thường Kiệt captured Qinzhou and Lianzhou prefectures. Lý Thường Kiệt calmed the apprehensions of the local Chinese populace, claiming that he was simply apprehending a rebel who took refuge in China and that the local Song authorities had refused to cooperate in detaining him. In the early spring of 1076, Thường Kiệt and Nùng Tông Đán defeated the Song militia of Yongzhou, and during a battle at Kunlun Pass, their forces beheaded the Governor-General of Guangnan West Circuit, Zhang Shoujie (d. 1076). Afterwards, the Lý forces then marched towards the city of Yongzhou, where they were temporarily held up by a fierce resistance led by the Yongzhou governor Su Jian, who with three thousand soldiers prevented the city from falling for forty-two days. After the forty-two-day siege, on March 1, 1076, Yongzhou was finally breached and then razed to the ground, as Lý forces massacred 58,000 people within the city. Prior to the massacre, after the city was lost, governor Su Jian and thirty-six members of his family in the city committed suicide, with Su Jian stating "I won't die at the hands of those thieves." Several sources estimate that the total number of people killed by Lý troops during this campaign totaled 100,000. When Song forces attempted to challenge Lý's forces, the latter retreated, with their spoils of war and thousands of prisoners.

Lý Thường Kiệt had fought a war with the Chams in 1069, and in 1076, the Song called upon their vassal states the Khmer Empire and Champa to go to war again against the Lý. At the same time, the Song commander Guo Kui (1022–1088) led the combined Song force of approximately 300,000 men against Lý, who were at the time simultaneously defending against incursions from the Khmer Empire and Champa. The Song quickly regained Quảng Nguyên prefecture and in the process captured the resistance leader Lưu Ký, the chieftain of Quảng Nguyên that had attacked Yongzhou in 1075. By 1077, the Song had destroyed two other Vietnamese armies and marched towards their capital at Thăng Long (modern Hanoi). Song forces were halted at the Nhu Nguyệt River (in modern Bắc Ninh Province), where Lý Thường Kiệt had built a defense system by placing spikes under the Như Nguyệt riverbed before tricking Song troops into the death trap, killing more than 1,000 Chinese soldiers and sailors. In avoiding this strong defense system, the commander of the Song army, Guo Kui decided to change the army's direction towards the nearby region of Phú Lương, where they then defeated Lý Thường Kiệt's forces in a major battle. As the Song forces took the offensive, while the Lý Dynasty had to strenuously hold on to their costly defensive front, Lý Thường Kiệt tried to boost the morale of his soldiers by citing a poem before his army named "Nam quốc sơn hà". However, Song forces eventually broke through his defense line and their cavalry advanced to within several kilometers of the capital city. The Vietnamese counterattacked and pushed Song forces back across the river while their coastal defenses distracted the Song navy. Lý Thường Kiệt also launched an offensive, but lost two Lý princes in the fighting at Kháo Túc River. According to Chinese sources, "tropical climate and rampant disease" severely weakened Song's military forces while the Lý court feared the result of a prolonged war so close to the capital.

As a result of mounting casualties on both sides, Thường Kiệt made peace overtures to the Song; the Song commander Guo Kui agreed to withdraw his troops since they had lost 400,000 men, but kept five disputed regions of Quảng Nguyên (renamed Shun'anzhou or Thuận Châu), Tư Lang Châu, Môn Châu, Tô Mậu Châu, and Quảng Lăng, while Đại Việt held control of the Yong, Qin and Lian prefectures. These areas now comprise most of modern Vietnam's Cao Bằng Province and Lạng Sơn Province. In 1082, after a long period of mutual isolation, Emperor Lý Nhân Tông of Đại Việt returned Yong, Qin, and Lian prefectures back to Song authorities, along with their prisoners of war, and in return Song relinquished its control of four prefectures and the county of Đại Việt, including the Nùng clan's home of Quảng Nguyên. Further negotiations took place from July 6 to August 8, 1084 and were held at Song's Yongping garrison in southern Guangnan, where Lý's Director of Military Personnel Lê Van Thình (fl. 1075–1096) convinced Song to fix the two countries' borders between Quảng Nguyên and Guihua prefectures.

Aftermath
An aftermath of the war that still exists today resulted from an agreement that was negotiated by both sides that fixed the two country's borders; the resulting line of demarcation exists largely unmodified to the present day.

In Vietnam
During the Lý defense against the Song counteroffensive in which Song forces nearly breached into the Đại Việt capital of Thăng Long, general Lý Thường Kiệt wrote a famous poem named Nam quốc sơn hà which he then recited in front of his army in order to boost the morale of his men before the battle of Nhu Nguyệt River. The poem, dubbed retroactively as Vietnam's first Declaration of Independence asserted the sovereignty of Đại Việt rulers over its lands. The poem reads:

In China
In China, the Siege of Yongzhou during the Lý invasion was depicted in a Lianhuanhua book, which is a type of small palm-sized picture books containing sequential drawings developed in China during the early 20th century. The illustration on page 142, painted by Xiong Kong Cheng (熊孔成), describes the bravery of Su Jian, who, with only three thousand men was able to put up a fierce, forty-two day, resistance against Lý forces before finally succumbing to vastly superior numbers.