From this turbulent era, the first independent Vietnamese polity emerged when the warlord Ngô Quyền defeated the Southern Han's forces in the First Battle of the Bạch Đằng River in 938.
Well aware of Song's military might, and eager to safeguard the independence of his country, Đinh Bộ Lĩnh obtained a non-aggression agreement in exchange for tributes payable to the Chinese court every three years.
In addition to managing relations with China, Đinh Bộ Lĩnh energetically reformed the administration and the armed forces of Vietnam in order to strengthen the foundations of the new state.
Đinh Bộ Lĩnh also instituted a rigorous justice system in which treason was punishable by being cooked in a vat of boiling oil or by being fed to a caged tiger, so as to provide a deterrent to all who threatened the new order in the kingdom.
The Song dynasty wanted to take advantage of the turbulent situation in Đại Cồ Việt in order to reestablish Chinese control over the country, and sent an army to invade Vietnam.
In this crisis, Lê Hoàn, the commander-in-chief of Đinh Bộ Lĩnh's army, stepped into the power vacuum, dethroned the child emperor, eliminated his opponents at court, and entered into illicit relations with the Empress Dowager Dương Vân Nga.