Tensions between slave and free states mounted with arguments over the relationship between the state and federal governments, as well as violent conflicts over the spread of slavery into new states. Abraham Lincoln, candidate of the largely antislavery Republican Party, was elected president in 1860. Before he took office, seven slave states declared their secession—which the federal government maintained was illegal—and formed the Confederate States of America. With the Confederate attack upon Fort Sumter, the American Civil War began and four more slave states joined the Confederacy. Lincoln's Emancipation Proclamation declared slaves in the Confederacy to be free. Following the Union victory in 1865, three amendments to the U.S. Constitution ensured freedom for the nearly four million African Americans who had been slaves, made them citizens, and gave them voting rights. The war and its resolution led to a substantial increase in federal power.
After the war, the assassination of Lincoln radicalized Republican Reconstruction policies aimed at reintegrating and rebuilding the Southern states while ensuring the rights of the newly freed slaves. The resolution of the disputed 1876 presidential election by the Compromise of 1877 ended Reconstruction; Jim Crow laws soon disenfranchised many African Americans. In the North, urbanization and an unprecedented influx of immigrants from Southern and Eastern Europe hastened the country's industrialization. The wave of immigration, lasting until 1929, provided labor and transformed American culture. National infrastructure development spurred economic growth. The 1867 Alaska purchase from Russia completed the country's mainland expansion. The Wounded Knee massacre in 1890 was the last major armed conflict of the Indian Wars. In 1893, the indigenous monarchy of the Pacific Kingdom of Hawaii was overthrown in a coup led by American residents; the United States annexed the archipelago in 1898. Victory in the Spanish–American War the same year demonstrated that the United States was a world power and led to the annexation of Puerto Rico, Guam, and the Philippines. The Philippines gained independence a half-century later; Puerto Rico and Guam remain U.S. territories.
At the outbreak of World War I in 1914, the United States remained neutral. Most Americans sympathized with the British and French, although many opposed intervention. In 1917, the United States joined the Allies, turning the tide against the Central Powers. After the war, the Senate did not ratify the Treaty of Versailles, which established the League of Nations. The country pursued a policy of unilateralism, verging on isolationism. In 1920, the women's rights movement won passage of a constitutional amendment granting women's suffrage. The prosperity of the Roaring Twenties ended with the Wall Street Crash of 1929 that triggered the Great Depression. After his election as president in 1932, Franklin D. Roosevelt responded with the New Deal, a range of policies increasing government intervention in the economy. The Dust Bowl of the mid-1930s impoverished many farming communities and spurred a new wave of western migration.
The United States, effectively neutral during World War II's early stages after Nazi Germany's invasion of Poland in September 1939, began supplying materiel to the Allies in March 1941 through the Lend-Lease program. On December 7, 1941, the Empire of Japan launched a surprise attack on Pearl Harbor, prompting the United States to join the Allies against the Axis powers. Participation in the war spurred capital investment and industrial capacity. Among the major combatants, the United States was the only nation to become richer—indeed, far richer—instead of poorer because of the war. Allied conferences at Bretton Woods and Yalta outlined a new system of international organizations that placed the United States and Soviet Union at the center of world affairs. As victory was won in Europe, a 1945 international conference held in San Francisco produced the United Nations Charter, which became active after the war. The United States, having developed the first nuclear weapons, used them on the Japanese cities of Hiroshima and Nagasaki in August. Japan surrendered on September 2, ending the war.