After suffering its first defeat to the West in the First Opium War in 1842, the Qing imperial court struggled to contain foreign intrusions into China. Efforts to adjust and reform the traditional methods of governance were constrained by a deeply conservative court culture that did not want to give away too much authority to reform. Following defeat in the Second Opium War in 1860, the Qing tried to modernize by adopting certain Western technologies through the Self-Strengthening Movement from 1861. In the wars against the Taiping (1851–64), Nian (1851–68), Yunnan (1856–68) and the Northwest (1862–77), the traditional imperial troops proved themselves incompetent and the court came to rely on local armies. In 1895, China suffered another defeat during the First Sino-Japanese War. This demonstrated that traditional Chinese feudal society also needed to be modernized if the technological and commercial advancements were to succeed.
In 1898 the Guangxu Emperor was guided by reformers like Kang Youwei and Liang Qichao for a drastic reform in education, military and economy under the Hundred Days' Reform. The reform was abruptly cancelled by a conservative coup led by Empress Dowager Cixi. The Guangxu Emperor, who had always been a puppet dependent on Cixi, was put under house arrest in June 1898. Reformers Kang and Liang would be exiled. While in Canada, in June 1899, they tried to form the Emperor Protection Society in an attempt to restore the emperor. Empress Dowager Cixi mainly controlled the Qing dynasty from this point on. The Boxer Rebellion prompted another foreign invasion of Beijing in 1900 and the imposition of unequal treaty terms, which carved away territories, created extraterritorial concessions and gave away trade privileges. Under internal and external pressure, the Qing court began to adopt some of the reforms. The Qing managed to maintain its monopoly on political power by suppressing, often with great brutality, all domestic rebellions. Dissidents could operate only in secret societies and underground organizations, in foreign concessions or in exile overseas.