In 1861, Magruder was commissioned as a brigadier general in the Confederate service. He was quickly promoted to major general. He commanded Confederate forces at Yorktown, Virginia, with great skill. However, his lack of aggressiveness during the Seven Days campaign led to his reassignment to the command of the District of Texas, New Mexico, and Arizona. His greatest success was his brilliant performance in the Battle of Galveston on January 1, 1863, which resulted in a temporary lift of the Union blockade. In August 1864, he was transferred to the command of the Department of Arkansas. On March 31, 1865, Confederate president Jefferson Davis returned Magruder to the command of the District of Texas, New Mexico, and Arizona, but only in time to witness the surrender of the Trans-Mississippi Department at Galveston on June 2, 1865.