In 993, Khitans under General Xiao Sunning invaded Korea, but retreated after truce negotiations with minister Seo Hui of Goryeo, establishing friendly relations between the two nations. In 1004, Khitans invaded China. Chinese forces were terribly defeated, and the Chinese were forced to pay tribute to the Liao emperor.
However, the tension between Goryeo and Liao created another war. In 1009, General Gang Jo of Goryeo led a coup against King Mokjong, killing the king and establishing military rule. In 1010, the alliance was broken and Liao attacked Korea for General Gang's treason. Also, Khitans claimed six garrison settlements east of the Yalu River, which Goryeo claimed as its territory in truce negotiations during 993. The Koreans fought fiercely but were defeated. However, the Goryeo king managed to retain his claim on the six garrison settlements. The Khitans retreated from the peninsula, with no great prize for the war, but they did not give up their hope of gaining the six garrison settlements and making Goryeo pay tribute.
Near the Garrison Settlement of Heunghwajin, there was a small stream. General Gang ordered the stream blocked until the Khitans began to cross it, and when the Khitans were mid-way across, he ordered that the dam be destroyed so that the water would drown much of the Khitan army. The damage was great, but the Khitans did not abandon their campaign in spite of the challenges represented by defenders and by winter conditions in the northwest. They pushed through to approach Kaesong, the capital, but were defeated by a force led by General Kang Kam-ch'an.
Koryo's led a massive attack that all but annihilated the Khitan army. Barely a few thousand of the Liao troops survived the bitter defeat at Kusong. Four years later, Koryo and the Liao dynasty reached a negotiated peace agreement and established normal relations. The Khitan never again invaded Koryo.