Khitan Invasions of Goryeo
The Khitan Liao invaded Goryeo three times between 993 and 1019. Goryeo repelled them through Seo Hui’s diplomacy and Gang Gam-chan’s victory at Gwiju.

이강철 · CC BY-SA 4.0 · Source
The Khitans destroyed Balhae in 926 and contended with Song. With Goryeo pursuing a northward policy and friendly with Song, the Khitans sought to subdue Goryeo before turning on Song.
In the first invasion (993) Seo Hui negotiated with Xiao Sunning and actually gained six garrisons east of the Yalu. In the second (1010) Emperor Shengzong, citing Gang Jo’s coup, led 400,000 men himself and burned Gaegyeong while King Hyeonjong fled as far as Naju; Yang Gyu harried the retreat and freed captives, and the Khitans withdrew on condition that Hyeonjong come to pay homage. When he did not, nor return the six garrisons, Xiao Paiya invaded with 100,000 men in 1018. Gang Gam-chan released a river dammed with cowhides at Heunghwajin and in 1019 crushed the Khitans at Gwiju.
A balance of power among Goryeo, Song and Liao followed. Goryeo built an outer wall around Gaegyeong (1029) and the Thousand-li Wall from the Yalu to Doryeonpo, and carved the first Tripitaka to protect the realm through the Buddha’s power.