Shafter served as a 1st lieutenant the Union Army's 7th Michigan Volunteer Infantry Regiment at the battles of Ball's Bluff and Fair Oaks.
By the end of the war, he had been promoted to brevet brigadier general of volunteers.