Traditionally, African Americans were Republicans because of the legacy of the Emancipation Proclamation. Prior to the Civil War, the Democratic Party were staunch supporters of slavery, and after the war they pushed for continued segregation. However, they eventually began alienating white Southerners and conservatives with programs like the New Deal and its successor, the Great Society proposals. Of the two, the New Deal was accepted much more favorably by both parties since virtually everyone in the country benefited from its relief programs. Still, it was the beginning of what would become a monumental shift in voter sympathies.
In response to the Great Society strategy, Republicans Richard Nixon and Barry Goldwater crafted the so-called Southern strategy in the late 60s. The Southern strategy deliberately appealed to anti-black racism to capitalize upon the drain of conservative white voters from the Democratic voting block. It worked, and bizarrely enough, the two parties inherited each others' demographics.
But the real nail in the coffin was Lyndon B. Johnson, a Democratic president, passing the Civil Rights Act of 1964. Before he signed it in, he was apocryphally quoted as saying this act would alienate the South from the Democratic Party for the next 25 years. If he indeed said this, he was only half right. We're going on 50 years now and the party lines haven't changed much. Its passing completely shattered the long-held belief that whites needed to "stick together" to prevent civil rights legislation. By the end of the Civil Rights Movement, the traditionally conservative, segregationist Southern Democrats were extinct.