With the outbreak of the Civil War, Anderson resigned his U.S. Army commission on April 25, 1861 and returned home. The Governor of North Carolina, John Willis Ellis, appointed him as colonel of the 4th North Carolina Infantry on July 16. Anderson commanded the Confederate garrison at Manassas, Virginia from October 14, 1861 to March 25, 1862. Anderson capably led his regiment at the Battle of Williamsburg in May 1862 and was rewarded a month later with a promotion to brigadier general on June 9. He was assigned command of a brigade in Major General D.H. Hill's division. In the Seven Days Battles, Anderson led his brigade at Gaines Mill. During the Battle of Malvern Hill on July 1, Anderson commanded both his own brigade and Brig. Gen Winfield Featherston's brigade of James Longstreet's division, as Featherston had been wounded the previous day at Glendale and his brigade's officer corps, having been decimated in the fighting, contained only inexperienced majors and captains. Anderson himself was wounded at Malvern Hill and command of his brigade fell to Col. Charles Tew of the 2nd North Carolina. While recovering, he was part of the defenses around Richmond, Virginia in July 1862, serving in the 4th Brigade of Major General G.W. Smith's Division.