In 1225 the Tran family, which had effectively controlled the Vietnamese throne for many years, replaced the Ly dynasty by arranging a marriage between one of its members and the last Ly monarch, an eight-year-old princess. Under the Tran dynasty (1225-1400), the country prospered and flourished as the Tran rulers carried out extensive land reform, improved public administration, and encouraged the study of Chinese literature. The Tran, however, are best remembered for their defense of the country against the Mongols and the Cham. By 1225, the Mongols controlled most of northern China and Manchuria and were eyeing southern China, Vietnam, and Champa. In 1257, 1284, and 1287, the Mongol armies of Kublai Khan invaded Vietnam, sacking the capital at Thang Long (renamed Hanoi in 1831) on each occasion, only to find that the Vietnamese had anticipated their attacks and evacuated the city beforehand. Disease, shortage of supplies, the climate, and the Vietnamese strategy of harassment and scorchedearth tactics foiled the first two invasions. The third Mongol invasion, of 300,000 men and a vast fleet, was also defeated by the Vietnamese under the leadership of General Tran Hung Dao. Borrowing a tactic used by Ngo Quyen in 938 to defeat an invading Chinese fleet, the Vietnamese drove iron-tipped stakes into the bed of the Bach Dang River (located in northern Vietnam in present-day Ha Bac, Hai Hung, and Quang Ninh provinces), and then, with a small Vietnamese flotilla, lured the Mongol fleet into the river just as the tide was starting to ebb. Trapped or impaled by the iron-tipped stakes, the entire Mongol fleet of 400 craft was sunk, captured, or burned by Vietnamese fire arrows. The Mongol army retreated to China, harassed enroute by Tran Hung Dao's troops.
The fourteenth century was marked by wars with Champa, which the Tran reduced to a feudatory state by 1312. Champa freed itself again by 1326 and, under the leadership of Cham hero Che Bong Nga, staged a series of attacks on Vietnam between 1360 and 1390, sacking Thang Long in 1371. The Vietnamese again gained the upper hand following the death of Che Bong Nga and resumed their southward advance at Champa's expense. Despite their earlier success, the quality of the Tran rulers had declined markedly by the end of the fourteenth century, opening the way for exploitation of the peasantry by the feudal landlord class, which caused a number of insurrections. In 1400 General Ho Quy-ly seized the throne and proclaimed himself founder of the short-lived Ho dynasty (1400-07). He instituted a number of reforms that were unpopular with the feudal landlords, including a limit on the amount of land a family could hold and the rental of excess land by the state to landless peasants; proclamations printed in Vietnamese, rather than Chinese; and free schools in provincial capitals. Threatened by the reforms, some of the landowners appealed to China's Ming Dynasty (1368-1644) to intervene. Using reinstatement of the Tran dynasty as an excuse, the Ming reasserted Chinese control in 1407.