The civil war involving the Lê-Trịnh and Mạc dynasties resulted in 1592, when the army of Trịnh Tùng conquered Hanoi and executed king Mạc Mậu Hợp. Survivors in the Mạc royal family fled into the northern mountains from the province of Cao Bằng and continued to rule there until 1677 https://raymondpvbhm.blogadvize.com/38033149/8kbet-an-overview