Lê 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.
oulipo:avoid_letter[o], detectable_format:constrained_response