In May 1861, when news arrived that his native Virginia had seceded, Pegram resigned his lieutenant's commission and returned home. In early July 1861, he accepted a commission as a lieutenant colonel and was assigned command of the 20th Virginia Infantry. His regiment was part of the brigade of Brig. Gen. Robert S. Garnett and served in western Virginia fighting Union troops under Maj. Gen. George B. McClellan. On July 11, 1861, cut off from Garnett's main body during the Battle of Rich Mountain, Pegram controversially surrendered his entire regiment to the Federals. Thus John Pegram became the first former U.S. Army officer to be captured while in Confederate service. His men were paroled, but Pegram was imprisoned for six months in Fort Warren in Boston harbor.