On April 17, 1861, five days after the Confederate attack on Fort Sumter, the state legislature voted to secede from the United States and join the newly organized Confederate States of America. Official action came in May, after the Confederacy promised to move its national capital from its provisional home in Montgomery, Alabama to Richmond. The city was located at the end of a long supply line, which made it difficult to defend, requiring the bulk of the Army of Northern Virginia and arguably the Confederacy's best troops and commanders. It became the main target of Union armies, especially in the campaigns of 1862 and 1864–65.
In addition to Virginia and Confederate government offices and hospitals, a railroad hub, and one of the largest slave markets, Richmond had the largest iron foundry and arms factory during the war, the Tredegar Iron Works, which turned out artillery and other munitions, including the 723 tons of armor plating that covered the CSS Virginia (the salvaged former steam frigate USS Merrimack), the world's first ironclad warship used in war, as well as much of the Confederates' heavy ordnance machinery. The Confederate States Congress shared quarters with the Virginia General Assembly in Jefferson's designed Virginia State Capitol, with the Confederacy's executive mansion, known as the "White House of the Confederacy", located two blocks away on Clay Street. The Seven Days Battles followed in late June and early July 1862, during which commanding Union General-in-Chief George B. McClellan threatened to take Richmond in the Peninsula campaign but ultimately failed.
Three years later, as March 1865 ended, Richmond became indefensible after nearby Petersburg and several remaining rail supply lines to the south and southwest were broken. On March 25, Confederate General John B. Gordon's desperate attack on Fort Stedman east of Petersburg failed. On April 1, Federal Cavalry General Philip Sheridan, assigned to interdict the Southside Railroad, met brigades commanded by Southern Gen. George Pickett at the Five Forks junction, smashing them, taking thousands of prisoners, and encouraging Union General-in-Chief Ulysses S. Grant to order a general advance. When the Union Sixth Corps broke through Confederate lines on the Boydton Plank Road south of Petersburg, Confederate casualties exceeded 5,000, or about a tenth of General Lee's defending army. Lee then informed President Jefferson Davis that he was about to evacuate Richmond.
Davis and his cabinet, along with the government archives and Treasury gold, left the city by train that night, as government officials burned documents and departing Confederate troops burned tobacco and other warehouses to deny their contents to the victors. On April 2, 1865, General Godfrey Weitzel, commander of the 25th Corps of the United States Colored Troops, accepted the city's surrender from the Mayor and a group of leading citizens who remained. The Union troops eventually managed to stop the raging fires but about 25% of the city's buildings were destroyed.
President Abraham Lincoln visited General Grant at Petersburg on April 3, and took a launch to Richmond up the James River the next day, while Jefferson Davis attempted to organize his remaining Confederate government further southwest at Danville. Lincoln met Confederate assistant secretary of War John A. Campbell, and handed him a note inviting Virginia's state legislature to end their rebellion. After Campbell spun the note to Confederate legislators as a possible end to the Emancipation Proclamation, Lincoln rescinded his offer and ordered General Weitzel to prevent the former Confederate state legislature from meeting. Union forces killed, wounded or captured 8,000 Confederate troops at Sayler's Creek southwest of Petersburg on April 6, as the Southerners continued a general retreat southwestward. General Lee continued to reject General Grant's surrender suggestions until Sheridan's infantry and cavalry moved around the shrinking Army of Northern Virginia and appeared in front of his withdrawing forces on April 8, cutting off the line of further retreat southwest. He surrendered his remaining approximately 10,000 troops at Appomattox Court House meeting General Grant the following morning at the McLean Home. Davis was captured on May 10 near Irwinville, Georgia and taken back to Virginia, where he was imprisoned for two years at Fort Monroe until freed on bail.
Richmond emerged a decade after the smoldering rubble of the Civil War to resume its position as an economic powerhouse, with iron front buildings and massive brick factories. Canal traffic peaked in the 1860s and slowly gave way to railroads, allowing Richmond to become a major railroad crossroads, eventually including the site of the world's first triple railroad crossing.