Anderson was born in the High Hills of Santee at Borough House Plantation (Hill Crest), near the town of Stateburg located in Sumter County, South Carolina. He was the son of Dr. William Wallace Anderson and his wife, Mary Jane Mackensie, and the grandson of American Revolutionary War hero and namesake Richard Anderson.
Anderson graduated from the United States Military Academy in July 1842, and was brevetted a second lieutenant in the 1st U.S. Dragoons. He served at the Cavalry School for Practice at the U.S. Army Barracks in Carlisle, Pennsylvania, in 1842.
In the Mexican-American War, Anderson took part in the Siege of Veracruz in March 1847 and then skirmishing near La Hoya on June 9. He fought in the Battle of Contreras on August 19, the skirmish near Augustin Atlapulco the following day, and the Battle of Molino del Rey on September 8. For gallantry during the fighting near San Agustin, he was brevetted to the rank of first lieutenant as of August 17. Anderson also participated in the fight for and capture of Mexico City from September 12–14.
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 the 2nd Division of Longstreet's First Corps.
At the Second Battle of Bull Run in August 1862, Anderson launched an attack that broke the Union lines and sent it retreating back toward the entrenchments around Washington, D.C. 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.
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 Union soldiers did. Reaching and defending this spot denied the Federals 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. Anderson was promoted to temporary lieutenant general on May 31.
When Longstreet returned from his convalescence on October 19, 1864, Anderson reverted to the rank of major general but led the newly created Fourth Corps through the Siege of Petersburg and the retreat towards Appomattox Court House in 1865. As the corps' survivors reformed and rejoined the army, what was left of the Third Corps was merged with the Second Corps on April 8. This left Anderson without a command and he proceeded home to South Carolina. Anderson was pardoned on September 27, 1865, although there is no record of his parole.
After the war, Anderson was a planter in Stateburg from 1866 to 1868, growing cotton. When that failed, he was then an agent of the South Carolina Railroad, working out of Camden from 1868 to 1878, and later a state phosphate inspector/agent in South Carolina 1879. He died at the age of 57 in Beaufort, and is buried in the old churchyard cemetery of St. Helena's Episcopal Church marked with the Southern Cross of Honor.