Opium Wars

The Opium Wars were two wars waged between the Qing dynasty and Western powers in the mid-19th century. The First Opium War, fought in 1839–1842 between the Qing and Great Britain, was triggered by the dynasty's campaign against the British merchants who sold opium to Chinese merchants. The Second Opium War was fought between the Qing and Britain and France, 1856–1860. In each war, the European force's modern military technology led to easy victory over the Qing forces, with the consequence that the government was compelled to grant favorable tariffs, trade concessions, and territory to the Europeans. 
The wars and the subsequently-imposed treaties weakened the Qing dynasty and Chinese governments, and forced China to open specified treaty ports (especially Shanghai) that handled all trade with imperial powers. In addition, China gave the sovereignty over Hong Kong to Britain. 
Around this time, China's economy also contracted slightly, but the sizable Taiping Rebellion and Dungan Revolt had a much larger effect.
First Opium War.
The First Opium War began in 1839 and was fought over trading rights, open trade, and especially diplomatic status. In the eighteenth century, China enjoyed a favourable trade balance with Europe, selling porcelains, silk, and tea in exchange for silver. In the late 18th century, the British East India Company expanded cultivation of opium in its Indian Bengal territories, selling it to private traders who transported it to China and passed it on to Chinese smugglers. By 1787, the Company was sending 4,000 chests of opium (each 77 kg) per year.
In earlier times, opium was taken as a relatively harmless medicine, but the new practice of smoking opium recreationally increased demand tremendously and often led to addiction. The Chinese Jiaqing Emperor issued edicts making opium illegal in 1729, 1799, 1814, and 1831, but imports grew as smugglers and colluding officials gorged on the profits. Some Americans entered the trade by smuggling opium from Turkey into China, including Warren Delano Jr., the grandfather of twentieth-century President Franklin D. Roosevelt, and Francis Blackwell Forbes, a relative of twenty-first-century Secretary of State John Forbes Kerry; in American historiography this is sometimes referred to as the Old China Trade. By 1833, the opium traffic soared to 30,000 chests. The East India Company sent opium to their warehouses in the free-trade region of Canton (Guangzhou), and sold it to Chinese smugglers.
In 1834, the East India Company's monopoly on the China trade ceased, as the illegal opium trade burgeoned. Partly concerned with the moral decay of the people and partly with the outflow of silver, the Emperor charged High Commissioner Lin Tse-hsu with ending the trade. In 1839, Commissioner Lin published in Canton, but did not send, an open Letter To Queen Victoria pleading for a halt to the opium contraband. Lin ordered the seizure of all opium in Canton, including that held by foreign governments and trading companies (called factories),
and the companies prepared to hand over a token amount to placate him. Charles Elliot, Chief Superintendent of British Trade in China, arrived 3 days after the expiry of Lin's deadline, as Chinese soldiers enforced a shutdown and blockade of the factories. The standoff ended after Elliot paid for all the opium on credit from the British Government (despite lacking official authority to make the purchase) and handed the 20,000 chests (1,300 metric tons) over to Lin, who had them destroyed at Humen.
Charles Elliott then wrote to London advising the use of military force against the Chinese. A small skirmish occurred between British and Chinese vessels in the Kowloon Estuary on 4 September 1839. After almost a year, the British government decided, in May 1840, to send troops to impose reparations for the financial losses of the British traders in Canton and to guarantee future security for trade. On 21 June 1840 a British naval force arrived off Macao and moved to bombard the port of Dinghai. In the ensuing conflict, the Royal Navy used its superior ships and guns to inflict a series of decisive defeats on the Chinese Empire.
The war was concluded by the Treaty of Nanking (Nanjing) in 1842, the first of Unequal Treaties between China and Western powers. The treaty forced China to cede in perpetuity the Hong Kong Island and surrounding smaller islands to the United Kingdom, and it established five treaty ports at Shanghai, Canton, Ningpo (Ningbo), Foochow (Fuzhou), and Amoy (Xiamen). The treaty also imposed a twenty-one million dollar payment to Great Britain, with six million, paid immediately and the rest through specified instalments thereafter. Another treaty the following year gave most favoured nation status to the British Empire and added provisions for British extraterritoriality. France secured the same concessions in treaties of 1843 and 1844.
Second Opium War.
In 1853, northern China was convulsed by the Taiping Rebellion, which established its capital at Nanking. In spite of this, a new Imperial Commissioner Ye Mingchen was appointed at Canton, determined to stamp out the opium trade, which was still technically illegal. In October 1856 he seized the "Arrow", a ship claiming British registration, and threw its crew into chains. Sir John Bowring, Governor of British Hong Kong, called up Admiral Sir Michael Seymour's fleet which on 23 October bombarded and captured the Pearl River forts on the approach to Canton, and proceeded to bombard Canton itself, but had insufficient forces to take and hold the city. On 15 December, during a riot in Canton, European commercial properties were set on fire and Bowring appealed for military intervention. The murder of a French missionary inspired support from France. 
The European allies, including Britain, France, and the Russian Empire, now sought greater concessions from China, including legalization of the opium trade, expansion of the transport of "coolies" (cheap labourers), opening all of China to British merchants and opium traffickers, and exempting foreign imports from internal transit duties. The war resulted in the Treaty of Tientsin (26 June 1858), which forced the Chinese to pay reparations for the expenses of the recent war, open a second group of ten ports to European commerce, legalize the opium trade, and grant foreign traders and missionaries rights to travel within China. After a second phase of fighting which included the sack of the Old Summer Palace and the occupation of the Forbidden City palace complex in Beijing, the Treaty was confirmed by the Convention of Peking in 1860.