You emphasize the 1964 election as the beginning of the transformation that occurred -- the switching of roles between the two major parties on matters of race. Certainly it was of huge importance, but the story should also include 1960.
For years, blacks had strongly supported Republicans, the heirs of Lincoln. On the other side, the Democrats did not challenge white supremacy in the South, and the Democratic coalition had relied on the "solid South" with its almost exclusively white electorate. For decades after Reconstruction ended, the Democratic Presidential candidate received all the electoral votes of the South except for a handful of elections in which a nationwide Republican landslide was powerful enough to put the Republican over the top in some Southern states.
It was in 1960 that the reversal began. From the Wikipedia article on the "Solid South":
In the 1960 election, the Democratic nominee, John F. Kennedy, continued his party's tradition of selecting a Southerner as the vice presidential candidate (in this case, Senator Lyndon B. Johnson of Texas). Kennedy and Johnson, however, supported civil rights. In October 1960, when Martin Luther King, Jr. was arrested at a peaceful sit-in in Atlanta, Georgia, Kennedy placed a sympathetic phone call to King's wife, Coretta Scott King, and Robert Kennedy helped secure King's release. King expressed his appreciation for these calls. Although King himself made no endorsement, his father, who had previously endorsed Republican Richard Nixon, switched his support to Kennedy.
Because of these and other events, the Democrats lost ground with white voters in the South, as those same voters increasingly lost control over what was once a whites-only Democratic Party in much of the South. The 1960 election was the first in which a Republican presidential candidate received electoral votes in the South while losing nationally. Nixon carried Virginia, Tennessee, and Florida.
Of course, 1964 was far more dramatic. Goldwater in 1964 and Stevenson in 1956 both lost in landslides, in which (except for Goldwater carrying his home state of Arizona) each found their only electoral votes in the deep South, including many of the same states. In just eight years, those states went from being the Democratic bastion to being the Republican bastion. The obvious reason, as you note, is that, as the Democratic Party embraced civil rights, the Republicans stepped into the breach of appealing to the racists who had long supported the Democrats.