The Lê dynasty, also known in historiography as the Later Lê dynasty (Vietnamese: Nhà Hậu Lê or Triều Hậu Lê, chữ Hán: 朝後黎, chữ Nôm: 茹後黎), was the longest-ruling Vietnamese dynasty, having ruled Đại Việt (chữ Hán: 大越) from 1428 to 1789 with an interregnum between 1527 and 1533. The Lê dynasty is divided into two historical periods: the Initial Lê dynasty (Vietnamese: triều Lê sơ or nhà Lê Sơ, chữ Hán: 朝黎初, chữ Nôm: 茹黎初; 1428–1527) before the usurpation by the Mạc dynasty, in which emperors ruled in their own right, and the Revival Lê dynasty (Vietnamese: triều Lê Trung hưng or nhà Lê Trung hưng, chữ Hán: 朝黎中興, chữ Nôm: 茹黎中興; 1533–1789), in which the emperors were figures who reigned under the auspices of the powerful Trịnh family. The Revival Lê dynasty was marked by two lengthy civil wars: the Lê–Mạc War (1533–1592) in which two dynasties battled for legitimacy in northern Vietnam and the Trịnh–Nguyễn Wars (1627–1672, 1774–1777) between the Trịnh lords in North and the Nguyễn lords of the South.
The dynasty officially began in 1428 with the enthronement of Lê Lợi after he drove the Ming Chinese army from Vietnam. The dynasty reached its peak during the reign of Lê Thánh Tông and declined after his death in 1497. In 1527, the Mạc dynasty usurped the throne; when the Lê dynasty was restored in 1533, the Mạc fled to the far north and continued to claim the throne during the period known as Southern and Northern Dynasties. The restored Lê emperors held no real power, and by the time the Mạc dynasty was finally eradicated in 1677, actual power lay in the hands of the Trịnh lords in the North and Nguyễn lords in the South, both ruling in the name of the Lê emperor while fighting each other. The Lê dynasty officially ended in 1789, when the peasant uprising of the Tây Sơn brothers defeated both the Trịnh and the Nguyễn, ironically in order to restore power to the Lê dynasty.
The Lê dynasty continued the Nam tiến expansion of Vietnam's borders southwards through the domination of the Kingdom of Champa and expedition into today Laos and Myanmar, nearly reaching Vietnam's modern borders by the time of the Tây Sơn uprising. It also saw massive changes to Vietnamese society: the previously Buddhist state became Confucian after the preceding 20 years of Ming rule. The Lê emperors instituted many changes modeled after the Chinese system, including the civil service and laws. Their long-lasting rule was attributed to the popularity of the early emperors. Lê Lợi's liberation of the country from 20 years of Ming rule and Lê Thánh Tông's bringing the country into a golden age was well-remembered by the people. Even though the restored Lê emperors' rule was marked by civil strife and constant peasant uprisings, few dared to openly challenge their power for fear of losing popular support. The Lê dynasty also was the period Vietnam saw the coming of Western Europeans and Christianity in early 16th-century.

History
Lam Sơn uprising (1418–1427)
During the Fourth Chinese domination of Vietnam, Lê Lợi led an uprising against the rule of the Ming dynasty in 1418, after resistance forces of two Trần dynasty princes Trần Ngỗi and Trần Quý Khoáng were crushed by the Ming army. He joined a secret Taoist swearing commentary in Lũng Nhai, Thanh Hoá in winter 1416, with other 18 men, who all swore they would fight against the Ming Chinese and restore Vietnamese independence and sovereignty.
The Lam Sơn ("blue mountain") campaign began on the day after Tết (Lunar New Year) in February 1418. In November 1424, the Lam Sơn captured the Nghệ An citadel in a surprise attack from their base in Laos, leading to the retreat of the ethnic-Vietnamese Ming commander Lương Nhữ Hốt (Liang Juihu) to the north. From their new base in high-density population Nghệ An, Lê Lợi's rebel forces captured the territory in modern-day central Vietnam, from Thanh Hoá to Đà Nẵng. By August 1426, the Lam Sơn rebellion launched an offensive to the north with new forces against a fresh Ming army commanded by Wang Tong in charge of defending northern Vietnam. The new Ming ruler, the Xuande Emperor, wished to end the war with Vietnam, but his advisors urged one more effort to subdue the rebellious province. Consequently, the Ming sent a large army of approximately 100,000 men to Vietnam. After the pivotal Battle of Tốt Động – Chúc Động in October 1426, the Ming dynasty withdrew by 1428. By early 1427, Lê Lợi's forces had controlled most of northern Vietnam, advancing as far as the southern tip of modern-day Guangxi. Following negotiations with the Ming, Lê Lợi selected Trần Cảo as a puppet king of Annam who nominally ruled from 1426 to 1428.
Early period (1428–1527)
Lê Lợi (1428–1433)
In 1428, Lê Lợi established the Lê dynasty and took the reign name Lê Thái Tổ, receiving recognition and formal protection from the Ming dynasty in a tributary relationship.In 1429, he introduced the Thuận Thiên code, largely based on the Tang Code, with severe charges for gambling, bribery and corruption. Lê Lợi granted a land reform in 1429 that took lands from people who collaborated with the Chinese and distributed them among landless peasants and soldiers. He distrusted many of his former generals, resulting in the 1430 execution of the two generals Trần Nguyên Hãn and Phạm Văn Xảo that is considered by Vietnamese historians as a political purge.Lê Lợi's reign would be short-lived, as he died in 1433.

Lê Thái Tông (ruled 1433–1442)
Lê Thái Tông (黎太宗, ruled 1433–1442) was the official heir to Lê Lợi. However, he was just eleven, so a close friend of Lê Lợi, Lê Sát, assumed the regency of the kingdom. Not long after he assumed the official title as Emperor of Vietnam in 1438, Lê Thái Tông accused Lê Sát of abuse of power and had him executed. In December 1435, Thái Tông ordered general Tư Mã Tây to subdue the Tày chief Cầm Quý who having a ten-thousand army of raiders in the northwest region.
In January 1436, the emperor ordered to make roads and canals from northwest region to the capital for showing the superior power of the Imperial court to the local tribes men. From 1437 to 1441, tribe men from Ai-Lao crossed the Annamite Range, raided in Thanh Hóa and southern Hưng Hóa (now Sơn La province) with the help of the local raiders led by Nghiễm Sinh Tượng were suppressed by the Imperial army. The Lê dynasty started treating hostilely to the ethnic minorities in western region. On a stone monument that was carved in 1439 under Thái Tông's reign said "Bồn-Man (Muang Phuan) barbarians were against our assimilation, they need to be exterminated to their roots, and with the Sơn-Man (Mường and Chứt) barbaric raiders, we need to eliminated all of them,..."
According to a Mạc–Trịnh version of Complete Annals of Đại Việt, the new Emperor had a weakness for women. He had many wives, and he discarded one favorite after another. The most prominent scandal was his affair with Nguyễn Thị Lộ, the wife of his father's chief advisor Nguyễn Trãi. The affair started early in 1442 and continued when the Emperor traveled to the home of Nguyễn Trãi, who was venerated as a great Confucian scholar.

Shortly after the Emperor left Trãi's home to continue his tour of the western province, he fell ill and died. At the time the powerful nobles in the court argued that the Emperor had been poisoned to death. Nguyễn Trãi was executed as were his three entire relations, the normal punishment for treason at that time.
Lê Nhân Tông (ruled 1442–1459)
With the Emperor's sudden death at a young age, his infant heir Bang Co was made emperor - although he was the second son of his father, his older brother Nghi Dân had been officially passed over due to his mother's low social status. Bang Co assumed the throne as Lê Nhân Tông (黎仁宗) but the real rulers were Trịnh Khả and the child's mother, the young Empress Nguyễn Thị Anh. The next 17 years were good years for Vietnam – there were no great troubles either internally or externally. Two things of note occurred: first, the Vietnamese sent an army south to attack the Champa kingdom in 1446; second, the Dowager Empress ordered the execution of Trịnh Khả, for reasons lost to history, in 1451.
In 1453 at the age of twelve, Lê Nhân Tông was formally given the title of Emperor. This was unusual as according to custom, youths could not ascend the throne till the age of 16. It may have been done to remove Nguyễn Thi Anh from power, but if that was the reason, it failed and the Dowager Empress still controlled the government up until a coup in 1459.

In 1459, Lê Nhân Tông's older brother, Nghi Dân, plotted with a group of followers to kill the Emperor. On October 28, the plotters with some 100 "shiftless men" infiltrated the palace and murdered the Emperor (he was just 18). The next day, facing certain execution the Dowager Empress committed suicide. The rule of Nghi Dân was brief, and he was never officially recognized as a sovereign by later Vietnamese historians. Revolts against his rule started almost immediately and the second revolt, occurring on June 24, 1460, succeeded. The rebels, led by Lê Lợi's surviving former advisors Nguyễn Xí and Dinh Liêt captured and killed Nghi Dân along with his followers. The rebels then selected the youngest son of Lê Thái Tông to be the new Emperor, who they proclaimed to be Lê Thánh Tông.
Lê Thánh Tông (ruled 1460–1497)
Quang Thuận Hoàng Đế (光順皇帝), whose reign was named Hồng Đức Thịnh Thế (洪德之盛治, "Prosperous reign of Hồng Đức"), instituted a wide range of government reforms, legal reforms, and land reforms. He restarted the examination system for selecting men for important government positions. He reduced the power of the noble families and reduced the degree of corruption in the government. He built temples to Confucius throughout the provinces of Đại Việt. In nearly all respects, his reforms mirrored those of the Ming dynasty. Thánh Tông was strongly influenced by his Confucian teachers and he resolved to make Việt Nam more like the Ming dynasty with its Neo-Confucianist philosophy and the key idea that the government should be run by men of noble character as opposed to men from noble families. This meant that he needed to take power away from the ruling families (mostly from Thanh Hóa province) and give power to the scholars who did well on the official examinations. The first step on this path was to revive the examination process, which had continued sporadically in the 1450s. The first examination was held in 1463 and, as expected, the top scholars were men from elsewhere- usually from the river delta surrounding the capital, not from Thanh Hóa.In 1467, Lê Thánh Tông changed the name of the state to "Thiên Nam" (Heavenly South) to make the parallel position with their northern neighbor and shared classical culture more explicit.
Thánh Tông encouraged the spread of Confucian values throughout Vietnam by having "temples of literature" built in all the provinces. There, Confucius was venerated and classic works on Confucianism could be found. He also halted the building of any new Buddhist or Taoist temples and ordered that monks were not to be allowed to purchase any new land.

Lê Thánh Tông introduced reforms designed to replace the Thanh Hoá oligarchy of Dai Viet's southern region with a corps of bureaucrats selected through the Confucian civil service examinations. Following the Chinese model, he divided the government into six ministries: Finance, Rites, Justice, Personnel, Army, and Public Works. Nine grades of rank were set up for both the civil administration and the military. A Board of Censors was set up with imperial authority to monitor governmental officials and reported exclusively to the emperor. However, governmental authority did not extend all the way to the village level. The villages were ruled by their own councils in Vietnam.
With the death of Nguyễn Xí in 1465, the noble families from Thanh Hóa province lost their leader. Soon they were mostly relegated to secondary positions in the new Confucian government of Thánh Tông. However, they still retained control over Vietnam's armies as the old general, Đinh Liệt, was still in command of the army. In the same year, Vietnam was attacked by Ryukyuan pirates from the northeast. This was dealt with by sending additional forces to the north to fight the pirates. Thánh Tông also sent a military force to the west to subdue the Ai-lao mountain tribes that was raiding the northwest border.In 1469, all of Vietnam was mapped and a full census was taken, listing all the villages in the Empire. Around this time the country was divided into 13 dao (provinces). Each was administrated by a Governor, Judge, and the local army commander. The emperor Thánh Tông also ordered that a new census should be taken every six years. Other public works that were undertaken included building and repair of granaries, using the army to rebuild and repair irrigation systems after floods, and sending out doctors to areas afflicted by outbreaks of disease. Even though the emperor, at 25, was relatively young, he had already restored Vietnam's stability, which was a marked contrast from the turbulent times marking the reigns of the two emperors before him.
Article 344 of the Nguyen dynasty code and Article 305 of the Le dynasty code both forbade self-castration and castration of Vietnamese men. Self-castration of Vietnamese men was banned by Lê Thánh Tông, the emperor, in 1464.

The Vietnamese under Emperor Le Thanh Tong cracked down on foreign contacts and enforced an isolationist policy. A large amount of trade between Guangdong (Leizhou Peninsula and Hainan) and Vietnam happened during this time. Early accounts recorded that the Vietnamese captured Chinese whose ships had blown off course and detained them. Young Chinese men were selected by the Vietnamese for castration to become eunuch slaves to the Vietnamese. It has been speculated by modern historians that Chinese who were captured and castrated by the Vietnamese were involved in regular trade between China and Vietnam instead of being blown off course, and that they were punished after a Vietnamese crackdown on trade with foreign countries.
A 1499 entry in the Ming Shilu recorded that thirteen Chinese men from Wenchang including a young man named Wu Rui were captured by the Vietnamese after their ship was blown off course while traveling from Hainan to Guangdong's Qin subprefecture (Qinzhou), after which they ended up near the coast of Vietnam, in the 1460s, during the Chenghua Emperor's rule (1464–1487). Twelve of them were enslaved to work as agricultural laborers, while the youngest Chinese man, Wu Rui (吳瑞) was selected by the Vietnamese court for castration since he was the only young man in among the thirteen and he became a eunuch at the Vietnamese imperial palace in Thang Long for nearly one fourth of a century. After years of serving the Vietnamese as a eunuch slave in the palace, he was promoted to a position with real power after the death of the Vietnamese ruler in 1497 to a military position in northern Vietnam as military superintendent since his service in the palace was apparently valued by the Vietnamese. However the Lạng Sơn guard soldier Dương Tam tri (Yang Sanzhi) (楊三知) told him of an escape route back to China and Wu Rui escaped to Longzhou after walking for 9 days through the mountains. The local ethnic minority Tusi chief Wei Chen took him into custody, overruling objections from his family who wanted to send him back to Vietnam. Vietnam found out about his escape and sent an agent to buy Wu Rui back from Wei Chen with 100 Jin in payment since they were scared that Wu Rui would reveal Vietnamese state secrets to China. Wei Chen planned to sell him back to the Vietnamese but told them the amount they were offering was too little and demanded more however before they could agree on a price, Wu was rescued by the Pingxiang magistrate Li Guangning and then was sent to Beijing to work as a eunuch in the Ming palace at the Directorate of Ceremonial (silijian taijian 司禮監太監). The Đại Việt sử ký toàn thư records that in 1467 in An Bang province of Dai Viet (now Quảng Ninh Province) a Chinese ship blew off course onto the shore. The Chinese were detained and not allowed to return to China as ordered by Le Thanh Tong. This incident may be the same one where Wu Rui was captured.
Several Malay envoys from the Malacca sultanate were attacked and captured in 1469 by Vietnamese navy as they were returning to Malacca from China. The Vietnamese enslaved and castrated the young from among the captured.
A 1472 entry in the Ming Shilu reported that some Chinese from Nanhai escaped back to China after their ship had been blown off course into Vietnam, where they had been forced to serve as soldiers in Vietnam's military. The escapees also reported that they found out that more than 100 Chinese men remained captives in Vietnam after they were caught and castrated by the Vietnamese after their ships were blown off course into Vietnam in other incidents. The Chinese Ministry of Revenue responded by ordering Chinese civilians and soldiers to stop going abroad to foreign countries. These 100 men were taken prisoner around the same time as Wu Rui and the historian Leo K. Shin believes all of them may have been involved in illegal trade instead of being blown off course by wind. The over 100 Chinese men who were castrated and made into eunuchs by the Vietnamese remained captives in Vietnam when the incident was reported. Both the incidents of the young Chinese man Wu Rui and the more than 100 Chinese men being castrated and used as eunuchs point to possible involvement in trade according to historians John K. Whitmore and Tana Li which was then suppressed by the Vietnamese government instead of them really being blown off course by the wind. China's relations with Vietnam during this period were marked by the punishment of prisoners by castration.
Under the order of Lê Thánh Tông, the official historical text of the Lê dynasty, Đại Việt sử ký toàn thư (大越史記全書), was compiled and finished in 1479. The 15-volume book covered the entirety of Vietnamese history at that point, from the Hồng Bàng dynasty to the enthronement of Lê Thái Tổ.
Hồng Đức's campaigns against Champa and Lan Xang (1471–1480)
In 1471, Lê Thánh Tông conquered Champa and captured the Cham capital Vijaya, ending independent Cham rule in the south. The Kingdom of Champa was reduced to a small enclave near Panduranga (modern day Phan Rang–Tháp Chàm) and Kauthara (now Nha Trang) with many Chams fleeing to Cambodia. Lê Thánh Tông created a new province out of former Cham land and allowed ethnic Vietnamese settlers to settle it. The conquest of the Cham kingdoms started a rapid period of expansion by the Vietnamese southwards into this newly conquered land. The government used a system of land settlement called đồn điền (屯田).
From 1478 to 1480, Lê Thánh Tông led an expedition against the kingdoms of Lan Xang and Lanna in today Laos and Northern Thailand. Laotians were overwhelmed, their capital Luang Prabang was captured. Laotians retreated to the jungles, where they waged two-years of guerrilla warfare against the Vietnamese. King of Lan Xang Chakkaphat Phaen Phaeo sought refuge in Lanna. Some of the Vietnamese army had reached the kingdom of Ava. The expedition ended inconclusively, many Vietnamese soldiers died because of the hostile climate and rampant diseases; The Vietnamese forces were unable to suppress the Laotian guerrillas, and then the Laotians were able to recapture their capital. As the Vietnamese withdrew their army through the kingdom of Muang Phuan in December 1479, they annexed and incorporated it into Ninh Protectorate (Trấn Ninh) in 1480.
Decline of the Early period
With the death of Lê Thánh Tông, the Lê dynasty fell into a swift decline (1497–1527).
Prince Lê Tăng, the eldest of Lê Thánh Tông's 14 sons, succeeded his father as Lê Hiến Tông (黎憲宗). He was 38 years old at the time of his father's death. He was an affable, meek and mild-mannered person. Due to his short period of rule and that he didn't pass many significant reforms, his reign is considered to be an extension of Lê Thánh Tông's rule. The new emperor was known to historical annals as Lê Hiến Tông. In early 1499, several high-ranking officials including Lê Vĩnh and Lê Năng Nhượng persuaded Hiến Tông to choose an heir in order to maintain the dynasty's and the nation's security and sustainability. Hiến Tông agreed; and although the emperor had two elder sons: Lê Tuân and Lê Tuấn, Lê Thuần was designed as crown prince due to his deep interest in intellectuality and Neo-Confucianism, which caused Hiến Tông to perceive him as being far superior to his two older brothers. He chose his third son, Lê Túc Tông (黎肅宗) to be his successor. In 1504, Lê Hiến Tông died at 44 years old. The 17 year old Lê Thuần inherited the throne. The Confucian annalists portrayed him as a relatively good emperor who released many prisoners, stopping several construction works that posed heavy burden on his subjects, as well as reducing tributes from vassals and holding high-ranking officials in high regard. He was also said to have maintained harmony in the court and the whole country. In the other hand, the annals also recorded a revolt broke in Cao Bằng, led by Đoàn Thế Nùng against the government. Lê Thuần sent troops to Cao Bằng, defeating and killing Đoàn Thế Nùng along with 500 rebels. However, he fell gravely ill and died just six months after assuming the throne.
Lê Uy Mục (黎威穆) was the second son of Emperor Lê Hiến Tông. In 1505, as older brother of Emperor Lê Túc Tông, he succeeded the throne, later known under posthumous name Uy Mục hoàng đế (威穆皇帝). Lê Uy Mục was portrayed by Neo-Confucianist chroniclers as being deeply contrasted to his predecessors Lê Thánh Tông, Lê Hiến Tông and Lê Túc Tông, who closely followed Neo-Confucianist principles in governing the nation. The first thing the new emperor did was to take revenge against those who had barred him from the throne by having them killed. Among his victims were the former emperor's mother – which was considered a shocking display of evil behavior. Lê Uy Mục was described by a Ming ambassador – as a cruel, sadistic, and depraved person, who wasted the court's money and finances to indulge his whims. Well aware that he was detested by his subjects, Lê Uy Mục protected himself by hiring a group of elite bodyguards to surround him at all times. Among them was Mạc Đăng Dung, who became very close to the emperor and eventually rose to the rank of general. Despite his precautions, in 1509 a cousin, whom Lê Uy Mục had put in prison, escaped and plotted with court insiders to assassinate the emperor. The assassination succeeded and the killer proclaimed himself emperor under the name Lê Tương Dực.
Lê Tương Dực (黎襄翼), posthumous name Tương Dực Hoàng đế (襄翼皇帝), proved to be just as bad a ruler as Lê Uy Mục. He reigned from 1510 to 1516, all the while spending down the imperial treasury, and doing nothing to improve the country. He was heedless to the reaction that his taxes caused throughout the country. Later in his reign, he spent extravagantly in building many colossal palaces in the imperial capital, Thăng Long. The most notable of those places was one known to the Vietnamese as Cửu Trùng Đài (九重臺, trans. "Nine-Leveled Tower"), designed by the emperor's favoured architect Vũ Như Tô. He also spent much time enjoying sexual activities with his concubines, many of whom were former concubines of Lê Hiến Tông and Lê Uy Mục. According to court chroniclers, he ordered the build of special boats for his nude concubines to row on large artificial lakes. As the result of the emperor's luxurious lifestyle and ignorance of state affairs, the people suffered considerable hardships. Many soldiers committed to build imperial palaces died due to diseases. As the government became increasingly unpopular, many rebellions broke out. The largest of them was that of Trần Cảo, a northerner who claimed to be an heir of the House of Trần. His rule ended in 1516 when a group officials and generals led by Trịnh Duy Sản stormed the palace and killed him.
Crisis and revolts
At 14 years old, nephew of Lê Tương Dực, prince Lê Y, was enthroned as the new emperor Lê Chiêu Tông (ruled 1516–1522). Factions within the court vied with one another for control of the government. One powerful and growing faction was led by Mạc Đăng Dung, a military leader who rose through the ranks. His growing power was resented by the leaders of two noble families in Vietnam: the Nguyễn, under Nguyễn Hoàng Dụ and the Trịnh, under Trịnh Duy Đại and Trịnh Duy Sản. After several years of increasing tension, the Nguyễn and the Trịnh left the capital Hanoi (then called Đông Đô) and fled south, with the Emperor "under their protection".
In 1524, Mạc Đăng Dung forces captured and executed the leaders of the revolt (Nguyễn Hoàng Du, Trịnh Duy Đại, and Trịnh Duy Sản). The revolt by the Trịnh clan and the Nguyễn clan was defeated for the moment. This was the start of a civil war with Mạc Đăng Dung and his supporters on one side and the Trịnh and the Nguyễn on the other side. Thanh Hóa Province, the ancestral home to the Trịnh and the Nguyễn, was the battle ground between the two sides. After several years of warfare, Emperor Lê Chiêu Tông was assassinated in 1522 by Mạc Đăng Dung's supporters. Not long after, the leaders of the Nguyễn and the Trịnh were executed. Mạc Đăng Dung was now the most powerful man in Vietnam.
Usurpation of Mạc Đăng Dung
The degenerated Lê dynasty, which endured under six rulers between 1497 and 1527, in the end was no longer able to maintain control over the northern part of the country, much less the new territories to the south. The weakening of the monarchy created a vacuum that the various noble families of the aristocracy were eager to fill. Soon after Lê Chiêu Tông fled south with the Trịnh and the Nguyễn in 1522, Mạc Đăng Dung proclaimed the Emperor's younger brother, Lê Xuân, as the new Emperor under the name Lê Cung Hoàng. In reality, the new Emperor had no power. Three years after Mạc's forces killed his older brother Lê Chiêu Tông, Lê Chiêu Tông was pressured by Mạc Đăng Dung to hang himself on 18 June 1527 in Bắc Sứ garden. Mạc Đăng Dung, being a scholar-official who had effectively controlled the Lê for a decade, murdered all the Lê imperial family members then proclaimed himself the new Emperor of Vietnam on 15 June 1527, ending (so he thought) the Lê dynasty (see Mạc dynasty for more details).
Mạc Đăng Dung's seizure of the throne prompted other families of the aristocracy, notably the Nguyễn and Trịnh, to rush to the support of the Lê loyalists. With the usurpation of the throne, the civil war broke out anew. Again the Nguyễn and the Trịnh gathered an army and fought against Mạc Đăng Dung, this time under the leadership of Nguyễn Kim and Trịnh Kiểm. The Trịnh and the Nguyễn were nominally fighting on behalf of the Lê emperor but in reality, for their own power.
Southern and Northern Dynasties (1533–1597)
The Lê loyalists under Lê Ninh, a descendant of the Imperial family, escaped to Muang Phuan (today Laos). Marquis of An Thanh Nguyễn Kim summoned the people who were still loyal to the Lê emperor and formed a new army to begin a revolt against Mạc Đăng Dung. Subsequently, Nguyễn Kim returned to Đại Việt and led the Lê loyalists in a sixty-year-long civil war. In 1536 and 1537, Nguyên Hòa sent two envoys to Beijing to ask the Jiajing Emperor of the Ming dynasty to send an army to fight against the Mạc to restore the Lê dynasty. Many Ming officials like Mao Bowen showed strong support for the Lê loyalists and urged Jiajing Emperor to prepare a military campaign. The Ming Emperor agreed.
In 1527, the Vũ Văn clan in Hà Giang and northern Hưng Hóa rebelled against Mạc Đăng Dung and set up their own government. Vu Van Uyen and his family were called Bầu lords. In 1534, after Nguyễn Kim forces recaptured Thanh Hóa, Vũ Văn Uyên allied with Lê loyalists and the Ming army to fight against the Mạc dynasty. But Mạc Đăng Dung himself in 1540 went and surrendered the Ming army, wishing for peace. Mạc Đăng Dung ceded the northeast Vietnamese coastal to the Ming dynasty in exchange for the promise that the Ming dynasty would never invade Vietnam again. The Chinese now recognized both Mạc and Lê legitimacy over Đại Việt and withdrew their army. Bầu Lords showed strong support for the Lê dynasty and refused to accept Trịnh family at the early stage of Trịnh–Nguyễn War. Later, they cooperated with the Trịnh. Bầu Lords lasted for nearly 200 years from 1527 to 1699.
In 1542, Lê army from Muang Phuan recaptured Nghệ An. Mạc general Dương Chấp Nhất surrendered. After capturing the region of Thanh Hóa and Nghệ An, the Revival Lê dynasty eventually recaptured three-quarters of their former kingdom. Inasmuch as the Mac dynasty ruled the northern portion of Đại Việt while the Lê dynasty ruled the remainder of the country, this time became known as the period of Northern and Southern dynasties.
In 1545, Nguyễn Kim was poisoned by Dương Chấp Nhất, a surrendered general of the Mạc dynasty. The power of imperial court was then passed to Nguyễn Kim's son-in-law Trịnh Kiểm who became the founder of the Trịnh lords. Since then the emperor had only become a figurehead, Trịnh Kiểm and his successors were the de facto rulers of the country and continued the war with the Mạc. The war had three actual fighting periods: 1533–1537, 1551–1564 and 1584–1592. During the early confrontation period, the Lê dynasty introduced personal firearms like matchlocks into their army and surprised the Mạc army.Trịnh Tùng succeed his father in 1570, established the Trịnh lords and launched a large-scale offensive against the Mạc army in January 1592. Unable to resist the forces of the Lê loyalists, in December 1592 the Mạc dynasty retreated to the north and established a new capital at Cao Bằng Province allying with the Ming dynasty of China as a tributary nation against the Lê dynasty.
Restored Lê (1597–1789)
In 1597, the Ming dynasty recognized the legitimacy of the Lê monarch. However, the Ming recorded that the Lê rulers were very dissatisfied with the Ming Empire because the Chinese also concurrently supported the Mạc dynasty. In 1589, Toyotomi Hideyoshi sent envoys to the Lê court in Thanh Hoá, asking the Vietnamese to join Japan's alliance against Ming China and Joseon Korea. Hideyoshi hoped that a three-pronged attack on the Ming dynasty—with Japan from the north, Vietnam to the south, and other Southeast Asian nations to the southwest—would weaken the Ming army and allow the attackers to prevail. Although some officials supported the plan, the Lê emperor Quang Hưng and his ministers recognized the overwhelming strength of the Ming empire; the Lê ministers further viewed Japan and other Southeast Asian nations as "barbarians" and formally refused the Japanese lord's invitation.
The Ming loyalist Chinese pirate Yang Yandi (Dương Ngạn Địch) and his fleet sailed to Vietnam to leave the Qing dynasty in March 1682, first appearing off the coast of Tonkin in north Vietnam. According to the Vietnamese account, Vũ Duy Chí 武惟志, a minister of the Vietnamese Lê dynasty came up with a plan to defeat the Chinese pirates by sending more than 300 beautiful Vietnamese singing girls and prostitutes carrying red handkerchiefs to the Chinese pirate junks on small boats. The Chinese pirates and northern Vietnamese girls had sex but the women then wet the gun barrels of the Chinese pirates ships with their handkerchiefs. They then left in the same boats. The Vietnamese navy attacked the Chinese pirate fleet who were unable to fire back with their wet guns. The Chinese pirate fleet, originally 206 junks, was reduced to 50–80 junks by the time it reached south Vietnam's Quang Nam and the Mekong delta. The Chinese pirates having sex with north Vietnamese women may also have transmitted a deadly epidemic from China to the Vietnamese which ravaged the Tonkin regime of north Vietnam. French and Chinese sources say a typhoon contributed to the loss of ships along with the disease. The Nguyễn court allowed Yang (Duong) and his surviving followers to resettle in Đồng Nai, which had been newly acquired from the Khmers. Duong's followers named their settlement as "Minh Huong", to recall their allegiance to the Ming dynasty.
Trịnh–Nguyễn contention
In 1620, Nguyễn Phúc Nguyên officially refused to send taxes to the court in Hanoi. A formal demand was made to the Nguyễn to submit to the authority of the court, and it was formally refused. In 1623 Trịnh Tùng died and was succeeded by his son Trịnh Tráng. Trịnh Tráng made yet another formal demand for submission, and again Nguyễn Phúc Nguyên refused. Finally in 1627 open warfare broke out between the Trịnh and the Nguyễn. For four months a large Trịnh army campaigned against the Nguyễn army but were unable to defeat them. The result of this war was that Vietnam had effectively been partitioned into northern and southern regions, with the Trịnh controlling most of the north and the Nguyễn controlling most of the south; the dividing line was the Gianh River in Quảng Bình Province. This border was very close to the Seventeenth parallel (in actuality the Bến Hải River located just to the south in Quảng Trị Province), which was imposed as the border between North Vietnam and South Vietnam during the 1954–1975 Partition of Vietnam.
While the Trịnh ruled over a much more populous territory, the Nguyễn had several advantages. First, they were on the defensive and as such were more motivated to fight. Second, the Nguyễn were able to take advantage of their contacts with the Europeans, specifically the Portuguese, to purchase advanced European weapons and hire European military experts in fortifications. Third, the geography was favorable to them, as the flat plains of the North suitable for large organized armies ended at Nguyễn-controlled territory; the mountains of the central highlands reach almost to the sea.
After the first campaign, the Nguyễn built two massive fortified lines which stretched a few miles from the sea to the central highlands. The walls were built north of Huế near the city of Đồng Hới. The Nguyễn defended these lines against numerous Trịnh offensives which lasted till 1672. Tradition holds that the builder of these walls was a Vietnamese general who was hired from the Trịnh court by the Nguyễn. Under his direction the walls held repeatedly against multiple Trịnh assaults, even when they mustered an army of 100,000 men, 500 elephants, and 500 large ships.In 1633 the Trịnh tried attacking the Nguyễn by sea to avoid costly assaults on the great walls. However, the Trịnh fleet was defeated by the Nguyễn fleet at the battle of Nhat-Le. Around 1635 the Trịnh decided to emulate the Nguyễn and sought military aid from the Europeans. Trịnh Tráng hired the VOC to make European cannons and ships for his army. In 1642–43, the Trịnh army attacked the Nguyễn walls. With the aid of the Dutch cannons, the Trịnh army broke through the first wall but failed to break through the second. At sea, the Trịnh, with their Dutch ships Kievit, Nachtegaels and Woekende Book were defeated at sea by the Nguyễn fleet with their Chinese style galleys. Trịnh Tráng staged yet another offensive in 1648 but at the battle of Truong Duc, the Trịnh army was again badly beaten by the Nguyễn. The new Lê emperor died around this time, perhaps as a result of the defeat. This now left the door open for the Nguyễn to finally go on the offensive.
The Nguyễn launched their own invasion of northern Vietnam in 1653. The Nguyễn army went north and defeated the weakened Trịnh army, capturing Quảng Bình and Hà Tĩnh Province. In the following year, Trịnh Tráng died as Nguyễn forces entered Nghệ An Province. Under the leadership of Trịnh Tráng's successor the capable Trịnh Tạc however, the northern army managed to defeat the Nguyễn army. The Nguyễn were also further weakened by a division between their two top generals who refused to cooperate with each other. In 1656 the Nguyễn army was driven back all the way to their original territories. Trịnh Tạc tried to break the walls of the Nguyễn in 1661 but this attack, like so many before it, failed.
In 1672, the Trịnh army made a last effort to conquer the Nguyễn. The attacking army was under the command of Trịnh Tạc's son, Trịnh Căn, while the defending army was under the command of Nguyễn Phúc Tần's son Prince Nguyễn Phúc Thuận. The attack, like all the previous attacks on the Nguyễn walls, failed. This time the two sides agreed to a peace. With the Qing dynasty under the Kangxi Emperor serving as mediator, the Trịnh and the Nguyễn finally agreed to end the fighting by making the Linh River the border between their lands (1673). Although the Nguyễn nominally accepted the Lê emperor as the legitimate and sole ruler of Vietnam. However, the reality was that the Nguyễn ruled the south, and the Trịnh, the north. This division continued for the next century. The border between the Trịnh and the Nguyễn was strongly fortified yet remained peaceful. Despite the de facto partition of the empire, both the ruling families of the two realms claimed to be loyal subjects under the authority of the singular imperial Lê family, and their territories were de jure all under the same empire, Đại Việt.
Tây Sơn rebellion
The stalemate between the Trịnh and the Nguyễn lords that began at the end of the 17th century did not, however, mark the beginning of a period of peace and prosperity. Instead the decades of continual warfare between the two families had left the ruists and peasantry in a weakened state, the victim of taxes levied to support the courts and their military adventures. Having to meet their tax obligations had forced many peasants off the land and facilitated the acquisition of large tracts by a few wealthy landowners, nobles, and scholar—officials. Because scholar—officials were exempted from having to pay a land tax, the more land they acquired, the greater was the burden that fell on those peasants who had been able to retain their land. In addition, the peasantry faced new taxes on staple items such as charcoal, salt, silk, and cinnamon, and on commercial activities such as fishing and mining. The disparate condition of the economy led to neglect of the extensive network of irrigation systems as well.