Ténh Hải quân or Jinghai Prefecture was an administrative division of the Tang dynasty of China administered by Chinese governors, which then later became a quasi-independent regime ruled by successive local Vietnamese warlords and monarchs. It was centered around what is now northern Vietnam from 866 to 967 during the late Tang period and lasted until the late Five Dynasties and Ten Kingdoms period when ÃÂinh Bá» Lénh established the ÃÂinh dynasty.
Jinghai Prefecture () was created in 866 by the Chinese general Gao Pian as a Tang fanzhen ("buffer town") in the former Annan Duhufu (Protectorate General to Pacify the South) after retaking it from Nanzhao, which had invaded and captured the area in 863. The area of the command was sometimes referred to as "circuit" (, ). In 875, the Huang Chao rebellion broke out in northern China. In 879, the rebels sacked Guangzhou, headed north, bypassing Guangxi and northern Vietnam. A campaign against local aboriginals in Jinghai was conducted from 874 to 879. In 880, the army in ÃÂại La mutinied, forcing the commander Zeng Gun to flee north, ending de facto Chinese control. Tang troops returned north in small groups of their own initiative. From 880 to 905, named holders of the post never actually governed Jinghai. In 904, Zhu Wen's brother Quanyu tried to enter the region but was immediately dismissed the next year for being "stupid and without ability."
In 905, the native chief Khúc Thừa Dụ of the Khúc clan came to power and proclaimed himself jiedushi. In 907, his son Khúc Hạo (Chu Hao) succeeded as governor and was recognized by the Later Liang dynasty in northern China. In southern China, the powerful Liu Yin ruled over Guangzhou and was a close ally of Zhu Quanzhong. In 908 Khúc Hạo sent his son Khúc Thừa Mỹ to Guangzhou to gather information on the Liu family. When Liu Yin died in 911, Thừa Mỹ sent gifts to the Later Liang court by a naval envoy from the Min Kingdom. In the fifth month of the year, Liu Yin's brother and successor was named military governor at Guangzhou only. In the last month of the year, an imperial envoy arrived at ÃÂại La to confirm Thừa Mỹ as military governor there. The Vietnamese Khúc family maintained a relationship with the Later Liang court through the Min state in Fujian. Wang Shenzhi called Thừa Mỹ's envoys "southern barbarian merchants".
In 917, Liu Yan proclaimed himself emperor of Southern Han. In 923, the Later Liang dynasty collapsed, so the Khúc family could no longer look north for legal and moral support. The Southern Han at Guangzhou controlled all of the Xi River basin; they were eager to add Ténh Hải quân to their realm and to reassemble the ancient inheritance of Zhao TuoâÂÂs kingdom of Nanyue. In October 930, Liu Yan sent an army to occupy ÃÂại La and met no resistance. Khúc Thừa Mỹ was captured and taken to Guangzhou, where he was allowed to live out his days quietly. In 931, a former vassal of the Khúc family, Dðáng ÃÂình Nghá» from Aizhou (modern-day Thanh Hoá and Nghá» An), raised a 3,000-men army of retainers whom he called his adopted sons. Dðáng ÃÂình Nghá» attacked the Southern Han army. The Southern Han general, Cheng Bao, failed to retake Ténh Hải from Dðáng ÃÂình Nghá» and therefore he was decapitated.
Dðáng ÃÂình Nghá» ruled Ténh Hải for 6 years. In 937, he was assassinated by Kiá»Âu Công Tiá» n, a military subject who had given his allegiance to the Southern Han state and seized power. Ngô Quyá»Ân, a former general and son-in-law of Dðáng ÃÂình Nghá»Â, marched north from Ai to avenge the death of his patron. The pro-Southern Han Kiá»Âu Công Tiá» n called Liu Yan for help. Liu Yan placed his own son, Liu Hongcao, in command of the expedition, granting him the titles Jinghai jiedushi and King of Jiao, sailed to the coast of Annam and headed inland up the Bạch ÃÂằng River, a northern arm of the Red River delta, to confront Ngô Quyá»Ân. Liu Yan himself set out from Guangdong, following his son's fleet with additional forces. In late 938, Ngô Quyá»Ân defeated the Southern Han fleet on the river by using barriers of sharpened stakes. When hearing the news that Liu Hongcao was killed, Liu Yan cried bitterly and withdrew his own fleet and returned to Guangzhou.
In February 939, Ngô Quyá»Ân abolished the title of military governor and proclaimed himself king, with the ancient town of Cá» Loa as his royal capital. Although he had defeated the Chinese dynasty of Southern Han, the government Ngô Quyá»Ân established afterward still largely followed a Chinese template down to the color of dress, which increasingly alienated his Viet subjects. He died in 944 and was succeeded by his brother-in-law Dðáng Tam Kha, who styled himself the "King of Peace" (Binh Vuong). Tam Kha was part of the anti-Chinese faction while Ngô Quyá»Ân's sons were still part of the Chinese-influenced elite. Ngô Quyá»Ân's eldest son, Ngô Xðáng NgáºÂp, fled to the Nam Sách River area, which was the center of Chinese settlement and influence, and enlisted the help of Pham Bach Ho, a prominent member of a local noble family. He was also aided by Kiá»Âu Công Hãn, who came from the same family as Kiá»Âu Công Tiá» n and held a grudge against the Dðáng family. Tam Kha tried to manipulate Ngô Quyá»Ân's second son, Ngô Xðáng VÃÂn, by adopting him and making him a military leader. In 950, Xðáng VÃÂn enlisted the aid of ÃÂá» Cảnh Thạc and deposed Tam Kha. Xðáng VÃÂn declared himself the "King of Southern Jin" in imitation of Chinese dynasties. In 951, Xðáng VÃÂn invited his brother Xðáng NgáºÂp to rule alongside him but Xðáng NgáºÂp usurped his rule and declared himself "King of the Heavenly Plan" (Thien Sack Vuong). NgáºÂp died in 954 and VÃÂn returned to the throne. He sent envoys to Guangzhou bearing tribute and requesting credentials from Southern Han. However Xðáng NgáºÂp then cancelled a visit from a Southern Han official before he could arrive.
From 951, Duke ÃÂinh Bá» Lénh of Hoa Lð began challenging royal authority. As the two kings prepared to march against Hoa Lð, Bá» Lénh sent his son ÃÂinh Liá» n as a hostage of good faith. The Ngô brothers responded by denouncing Bá» Lénh for not coming in person, securing Liá» n, and proceeding to attack Hoa Lð. After Liá» n escaped back to Hoa Lð, Bá» Lénh moved to make an alliance with Trần Lãm, a merchant and warlord of Cantonese origin. In 965, king Xðáng VÃÂn campaigned against a pair of villages on the border of Phong. While observing the battle from a boat in the river, he was shot and killed by a crossbowman lying in ambush. After Xðáng VÃÂn's death, warlords across northern Vietnam enlisted their own armies and took control the land. The kingdom dissolved into civil war, known as the Anarchy of the 12 Warlords. In the same year, Bá» Lénh subdued and mobilized àman tribes in the west, then attacked warlord Ngô NháºÂt Khánh in Sán Tây with 30,000 troops. Having gained the submission of Ngô NháºÂt Khánh, the grandson of Ngô Quyá»Ân, Bá» Lénh's force marched northwest in 966 and defeated warlord Kiá»Âu Công Hãn. Two years later, he defeated all the warlords, proclaimed himself emperor of ÃÂại Cá» Viá»Ât or ÃÂại Viá»Ât and moved the Vietnamese capital to Hoa Lð.