Although he believed slavery to be immoral, Abraham Lincoln was not an abolitionist when the Civil War broke out in 1861. The president’s stated goal in the early years of the war was strictly the preservation of the Union. Granting freedom from bondage to the nearly 4 million slaves in America was a secondary concern. “My paramount object in this struggle is to save the Union, and is not either to save or destroy slavery,” he wrote in a famous letter to Horace Greeley in August 1862. “If I could save the Union without freeing any slave, I would do it, and if I could save it by freeing all the slaves, I would do it, and if I could save it by freeing some and leaving others alone, I would also do that.”

Lincoln’s position would pivot, however, as the war progressed. By the fall of 1862, he had begun to believe that freeing the slaves could aid in his ultimate goal of reuniting the states as he saw the military benefit provided by the thousands of slaves who had fled their owners and joined the Union forces fighting behind enemy lines. After the hard-fought Union victory at the Battle of Antietam, Lincoln issued the preliminary Emancipation Proclamation, which declared that all slaves in areas still in rebellion on January 1, 1863, “shall be then, thenceforward, and forever free.” Since it did not apply to border states or slave-holding territory already seized by the North, the Emancipation Proclamation had a much greater symbolic than practical effect.

Since it was executed by a president exercising greatly expanded wartime powers, the president and his supporters were concerned that courts might rule the Emancipation Proclamation a temporary emergency measure invalid once the war concluded. Lincoln preferred to see abolition codified on the state level, and by early 1864 several states had in fact enacted laws prohibiting slavery. Radical Republicans and abolitionists, however, tried to convince the president that slavery would only be outlawed with an amendment to the U.S. Constitution.

Ohio Congressman James M. Ashley formally introduced a constitutional amendment to abolish slavery in the House of Representatives on December 14, 1863, and Missouri Senator John Brooks Henderson, although representing a slave-holding border state, followed suit in the Senate on January 11, 1864. The Republican-controlled Senate overwhelmingly approved the amendment three months later.

Passage in the House would be more difficult due to the greater power of Democrats, who favored states’ rights over federal action, and moderate Republicans who sought peace at any price, even if it meant the perpetuation of slavery. When the House voted on the amendment on June 15, 1864, it only garnered 93 votes, 13 short of the two-thirds majority required for passage. Only four Democrats broke ranks to vote in the amendment’s favor.

That summer, Lincoln’s position on the 13th Amendment continued to evolve. At his party’s convention, he pushed for a Republican platform that called for slavery’s “utter and complete extirpation,” and in accepting the nomination he for the first time called for a federal amendment banning slavery as “a fitting, and necessary conclusion” to the war.

Emboldened by the 1864 election that not only returned him to the White House but increased his party’s seats in Congress, Lincoln threw himself behind the effort to pass the amendment. In his annual message to legislators in December 1864, Lincoln made clear that he had no intention of waiting for the inauguration of the new Congress in March. “The next Congress will pass the measure if this does not,” he wrote. “May we not agree that the sooner the better?”

As the 2012 Steven Spielberg biopic “Lincoln” portrayed, the president and Secretary of State William Seward were willing to strong-arm border Unionists and horse-trade with reluctant Democrats to secure their votes or at least their abstentions in order to lower the threshold for a two-thirds majority. The administration took advantage of the timing of the lame-duck Congress by offering patronage jobs—and in one case an ambassadorship to Denmark—to defeated Democrats.

When a second vote on the amendment was taken on January 31, 1865, the outcome was still far from certain. Rumors of a Confederate peace overture made backers concerned that Democrats might not want to derail potential talks by passing an inflammatory measure. The chamber grew silent as House of Representatives Speaker Schuyler Colfax declared the results with a quiver in his voice: “On the passage of the joint resolution to amend the Constitution of the United States, the ayes have 119, the noes 56.” The measure passed by the narrowest of margins, with eight members abstaining. Sixteen Democrats, all but two lame ducks, joined the full slate of Republicans in approving the measure.

Following a short heartbeat of silence, the chamber erupted in celebration. Parliamentary rules were cast aside as congressmen cheered wildly and “wept like children.” In the gallery, men waved their hats and women waved their handkerchiefs. The thunder of a 100-gun salute outside the Capitol building relayed the news of the vote to the rest of the city.

Although it wasn’t legally necessary, Lincoln affixed his signature to the engrossed copy of the amendment the following day. That night, a jubilant crowd led by a brass band gathered by torchlight outside the White House and raised a great cheer when Lincoln’s lanky frame appeared in a central upper window of the portico. The president leaned outside and told his supporters that slavery had caused the Civil War and must be expunged so that it would never tear apart the country again. “This amendment is a king’s cure for all the evils,” he said. “It winds the whole thing up.” Before he left, Lincoln congratulated the country “upon this great moral victory.”

In spite of the celebration, the amendment would still not become the law of the land until the approval by three-fourths of the states, which occurred when Georgia approved the measure on December 6, 1865. The first constitutional amendment in 60 years enshrined in ink what hundreds of thousands had already written in blood—that slavery shall not exist within the United States.