The Ming dynasty (//) was the ruling dynasty of China – then known as the Great Ming Empire – for 276 years (1368–1644) following the collapse of the Mongol-led Yuan dynasty. The Ming dynasty was the last imperial dynasty in China ruled by ethnic Han Chinese. Although the primary capital of Beijing fell in 1644 to a rebellion led by Li Zicheng (who established the Shun dynasty, soon replaced by the Manchu-led Qing dynasty), regimes loyal to the Ming throne – collectively called the Southern Ming – survived until 1683.
The Hongwu Emperor (ruled 1368–98) attempted to create a society of self-sufficient rural communities ordered in a rigid, immobile system that would guarantee and support a permanent class of soldiers for his dynasty: the empire's standing army exceeded one million troops and the navy's dockyards in Nanjing were the largest in the world. He also took great care breaking the power of the court eunuchs and unrelated magnates, enfeoffing his many sons throughout China and attempting to guide these princes through the Huang-Ming Zuxun, a set of published dynastic instructions. This failed spectacularly when his teenage successor, the Jianwen Emperor, attempted to curtail his uncles' power, prompting the Jingnan Campaign, an uprising that placed the Prince of Yan upon the throne as the Yongle Emperor in 1402. The Yongle Emperor established Yan as a secondary capital and renamed it Beijing, constructed the Forbidden City, and restored the Grand Canal and the primacy of the imperial examinations in official appointments. He rewarded his eunuch supporters and employed them as a counterweight against the Confucian scholar-bureaucrats. One, Zheng He, led seven enormous voyages of exploration into the Indian Ocean as far as Arabia and the eastern coasts of Africa.
The rise of new emperors and new factions diminished such extravagances; the capture of the Zhengtong Emperor during the 1449 Tumu Crisis ended them completely. The imperial navy was allowed to fall into disrepair while forced labor constructed the Liaodong palisade and connected and fortified the Great Wall of China into its modern form. Wide-ranging censuses of the entire empire were conducted decennially, but the desire to avoid labor and taxes and the difficulty of storing and reviewing the enormous archives at Nanjing hampered accurate figures. Estimates for the late-Ming population vary from 160 to 200 million, but necessary revenues were squeezed out of smaller and smaller numbers of farmers as more disappeared from the official records or "donated" their lands to tax-exempt eunuchs or temples. Haijin laws intended to protect the coasts from "Japanese" pirates instead turned many into smugglers and pirates themselves.
By the 16th century, however, the expansion of European trade – albeit restricted to islands near Guangzhou like Macau – spread the Columbian Exchange of crops, plants, and animals into China, introducing chili peppers to Sichuan cuisine and highly productive corn and potatoes, which diminished famines and spurred population growth. The growth of Portuguese, Spanish, and Dutch trade created new demand for Chinese products and produced a massive influx of Japanese and American silver. This abundance of specie remonetized the Ming economy, whose paper money had suffered repeated hyperinflation and was no longer trusted. While traditional Confucians opposed such a prominent role for commerce and the newly rich it created, the heterodoxy introduced by Wang Yangming permitted a more accommodating attitude. Zhang Juzheng's initially successful reforms proved devastating when a slowdown in agriculture produced by the Little Ice Age joined changes in Japanese and Spanish policy that quickly cut off the supply of silver now necessary for farmers to be able to pay their taxes. Combined with crop failure, floods, and epidemic, the dynasty collapsed before the rebel leader Li Zicheng, who was defeated by the Manchu-led Eight Banner armies who founded the Qing dynasty.
The Mongol-led Yuan dynasty (1271–1368) ruled before the establishment of the Ming dynasty. Explanations for the demise of the Yuan include institutionalized ethnic discrimination against Han Chinese that stirred resentment and rebellion, overtaxation of areas hard-hit by inflation, and massive flooding of the Yellow River as a result of the abandonment of irrigation projects. Consequently, agriculture and the economy were in shambles, and rebellion broke out among the hundreds of thousands of peasants called upon to work on repairing the dykes of the Yellow River. A number of Han Chinese groups revolted, including the Red Turbans in 1351. The Red Turbans were affiliated with the White Lotus, a Buddhist secret society. Zhu Yuanzhang was a penniless peasant and Buddhist monk who joined the Red Turbans in 1352; he soon gained a reputation after marrying the foster daughter of a rebel commander. In 1356, Zhu's rebel force captured the city of Nanjing, which he would later establish as the capital of the Ming dynasty.
With the Yuan dynasty crumbling, competing rebel groups began fighting for control of the country and thus the right to establish a new dynasty. In 1363, Zhu Yuanzhang eliminated his archrival and leader of the rebel Han faction, Chen Youliang, in the Battle of Lake Poyang, arguably the largest naval battle in history. Known for its ambitious use of fire ships, Zhu's force of 200,000 Ming sailors were able to defeat a Han rebel force over triple their size, claimed to be 650,000-strong. The victory destroyed the last opposing rebel faction, leaving Zhu Yuanzhang in uncontested control of the bountiful Yangtze River Valley and cementing his power in the south. After the dynastic head of the Red Turbans suspiciously died in 1367 while a guest of Zhu, there was no one left who was remotely capable of contesting his march to the throne, and he made his imperial ambitions known by sending an army toward the Yuan capital Dadu (present-day Beijing) in 1368. The last Yuan emperor fled north to the upper capital Shangdu, and Zhu declared the founding of the Ming dynasty after razing the Yuan palaces in Dadu to the ground; the city was renamed Beiping in the same year. Zhu Yuanzhang took Hongwu, or "Vastly Martial", as his era name.
Hongwu made an immediate effort to rebuild state infrastructure. He built a 48 km (30 mi) long wall around Nanjing, as well as new palaces and government halls. The History of Ming states that as early as 1364 Zhu Yuanzhang had begun drafting a new Confucian law code, the Da Ming Lü, which was completed by 1397 and repeated certain clauses found in the old Tang Code of 653. Hongwu organized a military system known as the weisuo, which was similar to the fubing system of the Tang dynasty (618–907).