Updated at 3:35 p.m. ET
President Obama, delivering the eulogy at the funeral of the Rev. Clementa Pinckney, said the alleged killer of the pastor and eight other congregants at the Emanuel African Methodist Episcopal Church hoped to "terrorize and oppress" but that "God has different ideas."
Noting the public forgiveness expressed toward white shooting suspect Dylann Roof by families of the victims in Charleston, South Carolina, Obama said Roof "didn't know he was being used by God."
"Their church was a sacred place," he said, "not just for blacks, or Christians, but for every American who cares about the expansion of liberty. ... That's what the church meant."
"Blinded by hatred, the alleged killer could not see the grace surrounding him," the president said.
Following last week's shooting, Roof was apprehended by police. A website linked to him has since emerged, containing a racially intolerant manifesto and photos of the suspect posing with weapons and use of the symbols of Confederate rebellion. The mass shooting has sparked a national conversation about race and the use of Confederate iconography.
"For too long, we were blind to the pain that the Confederate flag has caused," he said.
"It's true that a flag did not cause these murders," Obama said, but added to loud applause: "The flag always represented more than just ancestral pride."
Removing the Confederate battle flag from South Carolina's capitol "would not be an act of political correctness," he said, it would be an acknowledgement, that "the cause for which they fought, the cause of slavery, was wrong."
"By taking down that flag, we express God's grace," he said. "But I don't think God wants us to stop there. For too long we have been blind to the way past injustices continue to shape the present."
He also spoke of the need for equal opportunity in the black community and of the need to tackle the "unique mayhem" caused by gun violence.
He led a rendition of the gospel hymn "Amazing Grace," concluding: "May God continue to shed his grace on the United States of America."
Earlier, a hearse carrying Pinckney's body was accompanied by a somber procession as it made its way toward the venue of the funeral. Hundreds of people, led by the church's interim leader, the Rev. Norvel Goff, followed behind on foot.
"Someone should have told the young man. He wanted to start a race war. But he came to the wrong place," the Rev. John Richard Bryant said.
Those wishing to pay respects to Pinckney waited for hours to ensure a place inside the arena. Jacob Reid of Summerville, S.C., was in line with his two teenage daughters. He told The Associated Press that the family woke up at 4 a.m. to get ready and make the drive to Charleston.
"The Rev. Pinckney really inspired them," Jacob Reid, a resident of Summerville, told the AP, referring to his daughters. "He was a gentleman, easy to talk with. Very humble."
Funerals for two others slain in last week's attack, Ethel Lance and the Rev. Sharonda Coleman-Singleton, were held Thursday amid tight security.