During the winter of 1864/1865, the Army of the James was reorganized, and Foster was placed in command of the 1st Division of the XXIV Corps, now under the command of John Gibbon. Foster notably led his division in an assault on Fort Gregg during the Union breakthrough at Petersburg. Foster's division was part of the Union force that blocked Robert E. Lee's line of retreat at Appomattox Court House, leading to the Confederate surrender there. Foster was brevetted to major general of U.S. volunteers on March 13, 1865.