In his eulogy for the Rev Clementa Pinckney, Obama suddenly began singing "Amazing Grace," quickly joined by ministers and some of the thousands who packed into the Emanuel African Methodist Episcopal Church in the city Charleston in South Carolina.
The nation's first black president called for gun control and efforts to eliminate poverty and job discrimination, and said the Confederate battle flag -- long a symbol of Southern US pride -- must be removed from places of honor.
The president came to eulogize the Rev Clementa Pinckney, a state senator and pastor of Emanuel, a church founded by the leader of a failed slave revolt and burned to the ground by angry whites in 1822.
After the American Civil War, the church led efforts to expand equal rights in the South, hosting civil rights leader Martin Luther King Jr during campaigns in South Carolina.
"We do not know whether the killer of Rev Pinckney and eight others knew all of this history," the president said.
"An act that he imagined would incite fear, and incrimination, violence and suspicion. An act he presumed would deepen divisions that trace back to our nation's original sin," Obama continued, his voice rising in the cadence of the preachers who preceded him.
Obama spoke plainly about the ugliness of America's racial history -- from slavery to the many ways minorities have been deprived of equal rights in more recent times. Taking down the Confederate flag is a righteous step, "but God doesn't want us to stop there," he said.
Slain along with Pinckney were Cynthia Hurd, 54; Tywanza Sanders, 26; Sharonda Singleton, 45; Myra Thompson, 59; Ethel Lance, 70; Susie Jackson, 87; and the Revs. Daniel Simmons Sr, 74, and DePayne Middleton-Doctor, 49.
America's first black president sang the hymn less than a mile from where thousands of slaves were sold and where South Carolina signed its pact to leave the union a century and a half earlier.
