Anderson chose to follow his home state and the Confederate cause, and he resigned from the U.S. Army (accepted on March 3, 1861) to enter service with the Confederate Army. Anderson accepted a commission as colonel of the 1st South Carolina Infantry Regiment as of January 28. He was given command of the Charleston 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.
After recovering, Anderson joined the Confederate Army of the Potomac in February 1862 (which was absorbed into the Army of Northern Virginia later in the spring) as a brigade commander. During the Peninsula Campaign, he distinguished himself at the Battle of Williamsburg in May, during the Battle of Seven Pines, and in the Seven Days Battles in June and July. At Glendale, he took temporary command of Maj. Gen. James Longstreet’s division. Because of his excellent performance on the Peninsula, he was promoted to major general on July 14, 1862, and was given command of General Benjamin Huger’s former division. As part of Longstreet’s corps, Anderson fought at Second Bull Run. His division engaged the final Union defensive line around Henry House Hill, but the sun was starting to go down and he did not press the attack.
During the Maryland Campaign, General Cadmus Wilcox’s division was added to Anderson’s command. At the Battle of Antietam in September 1862, he was in overall command at the sunken road, or “Bloody Lane”, in the center of the Confederate defense. He was wounded in the thigh and left the battle (his senior brigadier Roger A. Pryor taking over) without which his division began to falter and eventually succumb to Union flank attacks that routed them from their position. At the Battle of Fredericksburg that December, his division was not heavily engaged.
During the Battle of Chancellorsville in May 1863, while operating away from Longstreet’s command (because Longstreet was on detached duty near Suffolk, Virginia, at the time), Anderson pressed the Union left while Lt. Gen. Thomas J. “Stonewall” Jackson attacked the right. Anderson and Maj. Gen. Lafayette McLaws left the main battle line on May 3, and struck east to check the advance of Union Maj. Gen. John Sedgwick’s VI Corps that would have led into Gen. Robert E. Lee’s rear. Following the death of Stonewall Jackson on May 10, Lee reorganized his army from two into three corps. Anderson was admired enough by Lee to be considered for corps command, but instead his division was assigned to the new Third Corps, commanded by now Lt. Gen A.P. Hill, who outranked Anderson and was one of the senior-most generals in the army. After reorganizing, Anderson retained most of his existing command except for Brig. Gen Lewis Armistead’s brigade, which was reassigned to George Pickett’s division.