Magruder graduated from West Point in 1830, ranked 15 out of 42 in his class. He was assigned to the artillery school at Fort McHenry, Maryland. He served in garrison, on recruiting service, on the frontier, and fought in the Seminole War and the Mexican War, awarded 2 brevets. After the war he served in Maryland and California and was in command of Fort Adams at Newport, Rhode Island.
Nicknamed "Prince John," he was fond of lavish living, fashionable military dress and courtly behavior toward ladies while stationed at Newport. He was held as "the picture of the Virginia gentleman, the representative of chivalry." He was held as "the picture of the Virginia gentleman, the representative of chivalry." He commanded an artillery battery in Washington until the Civil War began.
At the formation of the Confederacy, Magruder promptly resigned his commission on April 20, 1861 and was commissioned as a Colonel in the Confederate army on May 16th. He was assigned to command of the artillery in and about Richmond on April 29th, and soon afterward was given charge of the Virginia State forces in that locality. Put in command of the District of Yorktown in May, he defeated the Union force at Big Bethel, the first big battle of the war, in which his success gave confidence to the Confederate soldiers everywhere. The Confederate victory helped to establish his fighting reputation. He remained in this command until February, 1862. Stationed at Yorktown, with about 12,000 men, confronting McClellan's Peninsula Campaign, he demonstrated his remarkable ability as a master of ruse and strategy, causing McClellan to believe that a force superior to his own disputed his advance. Magruder was not actively engaged at Seven Pines, but after Gen. Robert E. Lee took command, he was put in charge of the left wing of the Confederate army, and during the operations north of the Chickahominy River, was left before Richmond to engage the attention of the Union army.
At Yorktown and in holding the bulk of Major Gen. George B. McClellan's Union army south of the Chickahominy River during the battles of Mechanicsville, Gaines' Mill, and Savage's Station he showed "a certain aptitude for independent command..., and with it, the ability to bluff an adversary."
At Malvern Hill, however, Magruder performed poorly, due to drunkenness and recklessness. Under his orders, 9 brigades made a heroic charger against the Union position, but were repulsed with fearful slaughter. This led to his losing his command and falling into public disfavor. He was recalled to Richmond to defend his actions in the Seven Days' Campaign.
At this time, the Confederate government determined to prosecute more vigorously the war in the West and attempt to recover lost territory in Missouri and Louisiana. The Department of Trans-Mississippi was formed, and Magruder was sent to its command. A short time later, he was recalled to Richmond and subsequently assigned to the District of Texas. He remained there until the end of the war.
Magruder rescued his military reputation somewhat by capturing the U.S.S. Harriet Lane and later recapturing Galveston, Texas. He directed his attention at once to the defenseless condition of the Texas coast, and caused the equipment of 2 cotton clad gunboats. When the Union army attempted to occupy Galveston, he recaptured the town January 1, 1863, made prisoners of the garrison, and caused the whole Union blockade fleet to hoist the white flag, although the uninjured vessels afterward escaped. He continued in command, the district being enlarged to incluclude New Mexico and Arizona, and in March, 1864, sent most of his forces to reinforce Lieutenant Gen. Richard Taylor against Banks' Red River Campaign.
After the war, Magruder refused to apply for parole and fled to Mexico. There, he fought under Emperor Maximilian. When Maximilian was defeated, he returned to the United States. He lectured for a time upon his Mexican experience, at Baltimore and other cities, finally settling at Houston, Texas, in 1869.