President Obama delivered the eulogy at the funeral of South Carolina state Sen. Clementa Pinckney, the pastor who was fatally shot in his Emanuel AME Church along with eight others. (WhiteHouse.gov)

Standing in the pulpit, President Obama paused, bit his lip and collected his emotions. It was near the end of his eulogy for the Rev. Clementa Pinckney and eight faithful church members killed after Bible study last week in the basement of Emanuel African Methodist Episcopal Church here.

The crowd of nearly 6,000 in the College of Charleston arena waited as the president remained silent for several seconds. He already had delivered a roaring speech, more like a sermon, about the resiliency of the historic black church “built by blacks seeking liberty,” a rest stop for “the weary along the Underground Railroad,” a “sacred place” attended by the “good . . . decent . . . God-fearing people” who had been killed by a gunman who “presumed [he] would deepen divisions.”

The shooter could not have known that “he was being used by God” and perhaps failed to comprehend “the power of God’s grace,” Obama said.

Church mothers dressed in white waved their hands, encouraging him with traditional call-and-response shouts of “Amen!” and “Go on, now! Preach, Brother President, preach!”

Obama continued: “If we can find that grace, anything is possible. If we can tap that grace, everything can change.”

And then he began to sing acapella, offering a slow and soulful rendition of one of the great gospel standards: “Amazing grace, how sweet the sound, that saved a wretch like me. I once was lost, but now I’m found, was blind but now I see.”

Thousands rose to their feet, cheering as the president sang and the Mother Emanuel Church choir joined in.

Wilhelmenia Jones, 73, an usher at Nichols Chapel AME in Charleston, pushed up from her walker and cheered on Obama. “The president’s speech was awesome,” she would say later. “He let them know we got to move forward. Grace is free.”

Verlinda Anderson, 60, of Waterloo, S.C., said the president’s message was moving. God’s grace, she added, “is sufficient for all of us, regardless of color, whether you’re black, white, blue or green.”

Rose Smith, 83, a librarian, waved her right hand, the way church people do when they are emotionally moved by a sermon. “When he gets out of the White House,” she said, “he should go into preaching.”

Obama, who also invoked the names of the eight other victims during his eulogy, was both preacher and president during the ceremony, explaining to the rapt crowd that the killer could not have known that he would inspire unity rather than provoke division.

The suspect, Dylann Roof, 21, apparently motivated by racial hatred, is alleged to have killed the nine worshipers after a Wednesday night Bible study. “Blinded by hatred,” Obama said, “the alleged killer would not see the grace surrounding Reverend Pinckney and that Bible study group, the light of love that shone as they opened the church doors and invited a stranger to join in their prayer circle.”

The services were held in the arena, a block from Mother Emanuel, as Pinckney’s church is known, to accommodate the thousands of mourners who began lining up early in the hot sun. More than 5,000 people were turned away.

Outside the arena, distant cousins of Pinckney, 41, stood next to members of Congress and senators from the state capitol, where the body of Pinckney, who was a state senator, lay under the rotunda Wednesday. At Mother Emanuel, thousands of mourners continued to arrive, and the piles of flowers and cards grew.

Inside the arena, the president’s eulogy turned into a meditation on the meaning of grace and a call to action on the issues of guns and race, two of the thorniest and most divisive problems of his presidency.

He praised South Carolina Gov. Nikki Haley (R) for advocating the removal of the Confederate flag from the capitol grounds in Columbia after the killings.

“For too long, we were blind to the pain that the Confederate flag stirred in too many of our citizens,” Obama said. People cheered from the arena’s rafters. Elderly women rose from their chairs.

“It’s true, a flag did not cause these murders. But as people from all walks of life, Republicans and Democrats, now acknowledge — including Governor Haley, whose recent eloquence on the subject is worthy of praise — as we all have to acknowledge, the flag has always represented more than just ancestral pride.”

Haley sat near the stage. House Speaker John A. Boehner (R-Ohio), making his first trip aboard Air Force One during the Obama presidency, also was among the mourners.

Before the service, church ushers in black suits and white gloves led people to their seats. A choir from Mother Emanuel sang “Amazing Grace” and “He’s Done So Much for Me.” As they sang and waited, the crowd began doing the “Low Country clap,” a tradition that sounds like a clicking percussion.

A long procession of eulogizers followed, beginning their remarks before Obama’s motorcade had even begun its journey from the airport to the arena.

The Rev. Norvel Goff Sr., who preached the Sunday sermon at Emanuel AME four days after the shootings, introduced Haley, Rep. James E. Clyburn (D-S.C.), Charleston Mayor Joseph P. Riley and Democratic presidential hopeful Hillary Rodham Clinton.

“No evil can separate us from the love of God,” Goff thundered into the microphone.

Other eulogies from pastors, friends and cousins recalled Pinckney’s spirit and his last act, which Gerald Malloy, a state senator, noted was “to open his doors to someone he did not know, did not understand and did not look like him.”

The most powerful tribute came from Pinckney’s wife, Jennifer, who was in the church at the time of the attack and locked herself in an office with one of their two daughters when she heard the shots.

“You promised me you would never leave me!” she wrote in a letter to her husband, published in the funeral program. “You promised me we would be together for years to come! You promised me we would watch our children grow, get married and have children of their own. You promised me that we would grow old together and spend our latter years without the demands of the Church or the State.

“I feel robbed, cheated and cut short. I feel badly that our girls will never have their father to watch them grow. But I’m thankful for one consolation that your life was not in vain.”

As the president left the stage to meet with grieving family members, AME ministers prayed a final prayer. Then the family settled into a caravan of black limousines and headed for Pinckney’s burial in Marion County, S.C.

Steven Mufson contributed to this article.