The Beijing area is known to have been inhabited by prehistoric humans (Homo erectus pekinensis, or Beijing man) approximately 500,000 years ago. The earliest recorded settlement, in what is now southwest Beijing, dates back to around 1045 B. C. By 453–221 B. C. (the "Warring States" period), the site was home to a city called Ji, which was the capital of the Yan Kingdom.

In 1215, the city at the site of present-day Beijing was torched by the Mongol conqueror Genghis Khan (1162–1227), who built a new city called Dadu ("Great Capital"), or Khanbaliq. Later in the thirteenth century, under the rule of Kublai Khan (1215–1294), it became the capital of a vast empire, and it has been China's national capital almost continuously ever since. It was renamed Beiping ("Northern Peace") at the beginning of the Ming dynasty (1368–1644). In 1421, the third Ming emperor, Yongle, made the city his capital, and it assumed its present name of Beijing ("Northern Capital"). It was during this period that the present grid pattern of the central city was established, arranged around a north-south axis centering on the Imperial Palace. The city's design followed the traditional architectural principles of feng shui, a system of using space in a way intended to achieve maximum harmony between the human and natural worlds. In 1553 walls went up around the "outer city" to the south, enclosing suburbs that had grown up adjacent to the original city.

Under the Qing dynasty of the Manchus (1644–1911), Beijing underwent substantial renovation and expansion although the basic character of the city during the Ming period was largely preserved. The last century of Manchu rule was a period of foreign encroachment from without and political instability within. The city of Beijing was captured by French and British forces during the second Opium War (1858–60), and the Summer Palaces were burned down. Foreign forces attacked the city during the Boxer Rebellion (1898–1900) at the turn of the twentieth century, destroying many of its artistic and historical treasures. Beijing remained at the center of Chinese history following the 1911 revolution that ended Chinese imperial rule and placed the nationalist Kuomintang in power. At the conclusion of World War I (1914–18), it was the site of a historic demonstration in Tiananmen Square, opposing Chinese capitulation to the terms of the Versailles Treaty (signed in 1919, the Versailles Treaty officially ended World War I).

Military and political developments in the second quarter of the twentieth century affected the status of Beijing. Fighting to regain control of the country from the warlords who had seized power shortly after the revolution of 1911, the Kuomintang (the Chinese Nationalist Party), under Chiang Kaishek, moved its capital to Nanjing in 1928 and renamed Beijing, calling it Beiping ("Northern Peace" instead of "Northern Capital"). In 1937 the Japanese seized control of the city when they invaded China, and it remained under occupation until the end of World War II (1939–45), with Chungking serving as the temporary Nationalist capital during the bitter warfare of that period. Beijing was retaken and held by the Kuomintang during the ensuing civil war, but the city finally fell to the Communists under the leadership of Mao Zedong (1893–1976) in January, 1949, and became the capital of the People's Republic of China the following October, regaining its former name and its position as the nation's political, cultural, and financial hub.

Under Mao's leadership, the city underwent modernization, as streets were widened, vestiges of imperial rule were demolished, and technical advisers from the Union of Soviet Socialist

The Summer Palace, featuring traditional Chinese gardening, was burned down by the allied forces of Great Britain and France in the second Opium War (1858–60). ()
Republics (U.S.S.R.) introduced examples of Soviet-style architecture. From 1966 to the late 1970s, life in Beijing, as elsewhere in China, was dramatically affected by the Cultural Revolution. Beijing's Tiananmen Square was the site of the 1976 demonstration, honoring deceased political leader Zhou Enlai, that marked the beginning of the end for this disastrous campaign of political repression.

For the final time in the twentieth century, Beijing's Tiananmen Square became the stage for a major political event, as the student-led pro-democracy movement was crushed there in the spring of 1989, accentuating the disparity between the country's economic reforms and its continuing level of political repression. Although China's human rights record continues to draw criticism from abroad and dissent at home, the economic liberalization of the past two decades has changed the face of its capital, with the construction of skyscrapers, the proliferation of the services and conveniences that characterize a modern consumer economy, and the exponential growth of tourism.