President Obama challenged the nation Friday to confront the “terrible toll of gun violence” a day after a white man opened fire in a historic black church, killing nine people whose mourning relatives addressed the alleged killer for the first time with a message of despair and forgiveness.

In an emotional courtroom encounter here, a mother and daughter, a sister and grandson, among others, spoke directly to Dylann Roof, the 21-year-old charged Friday with nine counts of murder. He appeared for the bond hearing from jail through closed-circuit television.

As Roof’s face filled much of the screen — his eyes lowered, two guards in body armor flanking him from behind — surviving relatives told Roof his crime had devastated their families. But some said they forgave him, and, recalling the spirit of the venue where he staged his attack, pledged to pray for his soul.

“We welcomed you Wednesday night in our Bible study with welcome arms,” Felicia Sanders, whose son Tywanza Sanders was allegedly killed by Roof. Police say Roof spent an hour among the parishioners Wednesday evening before opening fire.

“Tywanza Sanders was my son. But Tywanza Sanders was my hero. Tywanza was my hero,’’ she said, her voice trembling. “May God have mercy on you.”

Dylann Roof is in custody after police say he opened fire at a historic African American church in Charleston, SC. Here’s a look at the 21-year-old's background, including recent arrests, and what authorities say happened inside the church. (Alice Li/The Washington Post)

Thousands of miles away, addressing the U.S. Conference of Mayors in San Francisco, Obama spoke angrily about Charleston, which joins a grim roll call of cities such as Newtown, Conn., Aurora, Colo., and Oak Creek, Wis., where mass shootings have occurred during his time in office.

His frustration was directed primarily at Congress, which failed to pass a set of publicly popular gun control bills that he pushed after the December 2012 elementary school shootings in Newtown, where 20 children and six others were killed.

“We don’t know if it would have prevented what happened in Charleston,” Obama said. “But we might still have some more Americans with us. We might have stopped one shooter. Some families might still be whole. You all might have to attend fewer funerals.

“And we should be strong enough to acknowledge this,” he said.

The force of his words signaled a shift from his comments at the White House a day earlier. Then, he expressed a sense of resignation that any gun control measures, while needed to prevent another mass shooting, would likely happen “at some point” after he left office.

“I’m not resigned. I have faith we will eventually do the right thing,” Obama said Friday without offering specific policy proposals of his own. “You don’t see murder on this kind of scale, this kind of frequency in any other advanced nation on earth.”

The attack inside the Emanuel African Methodist Episcopal Church has left Charleston in mourning and a nation, from the president to parishioners here, struggling to understand and explain the aftermath.

A breakdown of the Charleston church shooting

The shooting was the deadliest attack on a place of worship in the United States since 1991, when nine people were killed at the Wat Promkunaram temple near Phoenix.

Authorities announced Friday that Roof had been charged with nine counts of murder and possession of a weapon during the commission of a violent crime.

His attorney has not commented, though his family issued a statement Friday extending sympathies to the victims and asking for privacy.

“Words cannot express our shock, grief and disbelief as to what happened that night,’’ the statement said.

More evidence also emerged that Roof, a high school dropout with a criminal record that began this year, may have been motivated by racial hatred. Law enforcement officials said he had confessed, and that during the confession, expressed strong anti-black views. Officials characterized him as unrepentant and unashamed.

Roof told officers that he wanted word of his actions to spread, said the officials, who spoke on the condition of anonymity because the investigation is ongoing.

Yet Roof also acknowledged to authorities that he had briefly reconsidered his plan during the time he spent watching the Bible study group after entering the church, two people briefed on the investigation said.

Roof said he “almost didn’t go through with it because they were so nice to him,” one of the people said, before he concluded that “I had to complete my mission.”

As he methodically fired and reloaded several times, the person said, Roof called out: “You all are taking over our country. Y’all want something to pray about? I’ll give you something to pray about.”

An affidavit filed by Charleston police detective Richard Burckhardt said the time that Roof spent with parishioners before opening fire amounted to about an hour.

The document does not state what, if anything, occurred in the moments before the shooting. But it says all victims were hit multiple times.

Before leaving the church, the affidavit states, Roof stood over someone “and uttered a racially inflammatory statement to the witness.”

South Carolina’s governor on Friday urged prosecutors to seek the death penalty for the shootings. “We will absolutely want him to have the death penalty,” Gov. Nikki Haley told NBC’s “Today” show.

But prosecutors said the decision about whether to seek execution had not yet been made. The prosecutor pursuing the case, Scarlett A. Wilson, said at news conference that she will make the decision after speaking to relatives of the victims.

“They deserve to know the facts first. They deserve to be involved in any conversations regarding the death penalty,” Wilson said.

Meanwhile, a federal civil rights investigation into the attacks was also underway, which authorities said will be conducted along with the state probe. Federal officials have described it as a hate crime investigation.

When Roof was arrested — about 250 miles from Charleston in neighboring North Carolina — he had a Glock .45-caliber semiautomatic handgun that law enforcement officials said he obtained in April, either receiving it as a birthday gift or buying it himself with birthday money. The gun was purchased legally, officials said.

At Roof’s bond hearing, Nadine Collier, the daughter of 70-year-old shooting victim Ethel Lance, was among those who addressed him.

“I forgive you,” Collier said, her voice breaking. “You took something very precious from me. I will never talk to her again. I will never, ever hold her again. But I forgive you. And have mercy on your soul.”

Roof is being held on a $1 million bond.

Horwitz and Markon reported from Washington. Anne Gearan in Charleston; Ken Otterbourg in Shelby; and Brian Murphy, J. Freedom du Lac, Mark Berman, Thad Moore and Julie Tate in Washington contributed to this report.