Anderson resigned from the U.S. Army (accepted on March 3, 1861) to enter service with the
Confederate States Army. Anderson accepted a commission as colonel of the 1st South Carolina Regulars on January 28. He was given command of the
Charleston, South Carolina harbor area after the capture of
Fort Sumter that April. He was promoted to
brigadier general on July 19 and transferred to
Pensacola, Florida, where he was wounded in the left elbow during the
Battle of Santa Rosa Island on October 9. and was promoted to
major general on July 14 and received command of General
Benjamin Huger's former division. On July 3, Anderson's brigades participated in the waning minutes of Pickett's Charge, but both were driven back.
Wilderness and Spotsylvania , actions May 10, 1864 During the spring of 1864, at the
Battle of the Wilderness, Longstreet was severely wounded, and Anderson took command of the First Corps, leading it throughout the
Overland Campaign. After the Wilderness, he fought well at the
Battle of Spotsylvania Court House. Anderson and his corps executed an all-night forced march on May 7 that secured that important position (reinforcing the Confederate cavalry earlier sent there) and arrived just before U.S. soldiers did. Reaching and defending this spot denied the U.S. soldiers a way around Lee's army towards
Richmond, and Anderson held it during heavy fighting from May 8–12. Anderson then fought at the
Battle of Cold Harbor in early June and participated in the rest of the Army of Northern Virginia's operations to the south of
Petersburg, Virginia, from mid-June until October. When Longstreet returned from his convalescence on October 19, 1864, Lee created the new
Fourth Corps, which Anderson led through the
Siege of Petersburg and the
retreat towards
Appomattox Court House in 1865. Because of several attacks by U.S. cavalry nipping at his corps, Anderson was forced to slow, occasionally stop, and beat off the attacks. This caused the Confederates to become isolated from the rest of Lee's army, moving west, and they were now the army's
rear guard. The corps finally halted and fought at
Sayler's Creek on April 6, which ended in a rout, and as Lee witnessed it, he exclaimed, "Has the army been dissolved?" As the corps' survivors reformed and rejoined the army, what was left of the Fourth Corps was merged with the Second Corps on April 8. This left Anderson without a command, and he proceeded home to South Carolina. Anderson assumed command of M. H. Hannon's Cavalry Brigade after Hannon was wounded at Monroe's Crossroads. Anderson was pardoned on September 27, 1865, although there is no record of his parole. ==Postbellum career and death==