Specifically, slavery was legal in the Union slave states of Missouri, Delaware, Maryland and Kentucky until the ratification of the 13th amendment in December of 1865, 8 months after the surrender of the Confederacy.
Slavery was ended in Maryland and Missouri before the end of the war.