Neither slavery nor involuntary servitude, except as a punishment for crime whereof the party shall have been duly convicted, shall exist within the United States, or any place subject to their jurisdiction.
In 1864 The Senate passed the 13th Amendment with vote of 38 to 6 but the bill was defeated by the Democrats in the House. After Lincoln’s re-election, he encouraged Congress to reconsider the bill. It was passed on January 31, 1865. It was voted for by 100% of the Republicans in Congress and 23% of the Democrats.
It was then sent to the states for ratification (approval), which happened in December 1865.
Lincoln had issued the Emancipation Proclamation in 1963. It had freed slaves in the states that were in rebellion. It meant that once areas were taken and put under control of Union troops, the slaves in those areas could be freed.
Slavery continued in the border states of Delaware and Kentucky throughout the war and only ended there when the 13th Amendment went in effect.
Read more:
Historynet.com: Abolitionist Movement
History.com: House Passes the 13th Amendment
History.com: The 13th Amendment is Ratified