Washington — He had done it before, after Tucson, Aurora, Fort Hood and Sandy Hook: taken on the mantle of the pastor-in-chief before a crowd of mourners for lives taken too soon by a man with a gun.
But when President Obama stood among African-American bishops in Charleston, S.C., to eulogize the minister slain with eight of his flock after welcoming the stranger to their Bible study, what he did was unlike anything he'd done before.
After eulogizing the Rev. Clementa Pinckney and discussing the moral and spiritual dimensions of racial hatred and gun violence, the president broke out into the first stanza of "Amazing Grace," bringing the overflow crowd in Charleston's TD Arena along with him.
"It was like — wow. Wow," said Bishop Vashti McKenzie, who was standing just behind Obama when he spoke at the June 26, 2015 funeral.
McKenzie, who heads the African Methodist Episcopal Church's General Board, said the speech was an answer to those who questioned if this president — who some had thought was reticent about his faith and about his role as the nation's first black president — was a Christian.
"It reminded us that he is a man of faith," the bishop added. "And it said a lot for his faith and it said a lot to the faith community."
But aside from that noteworthy moment, the 44th president has had successes and failures in calming the nation's culture wars.
"It's been a mixed legacy" for both sides of a divided country, said former White House staffer Michael Wear, author of the forthcoming book "Reclaiming Hope: Lessons Learned in the Obama White House about the Future of Faith in America."
One of Obama's earliest executive orders kept open the doors of the Office of Faith-based and Neighborhood Partnerships started by his predecessor George W. Bush under a slightly different name.
Over the course of eight years, beneficiaries of government-funded religious social services have won greater religious liberty protections and an interfaith college initiative has grown to include hundreds of campuses involved in service projects.
His advisory councils of religious and secular leaders have included transgender, Sikh and evangelical members, and have promoted goals such as eliminating poverty, preventing lead poisoning, and improving relations between communities and law enforcement.
But the administration also maintained a rule that has roiled church-state separation activists because it allows government-funded religious organizations to hire based on faith.
It was a rule Obama had promised to change.
"If you get a federal grant, you can't use that grant money to proselytize to the people you help and you can't discriminate against them — or against the people you hire — on the basis of their religion," he said in 2008.
For the Rev. Barry Lynn, executive director of Americans United for Separation of Church and State, it was a big disappointment.
"There's no question that the worst provision, the worst policy contained now in both the Bush setup of the program and the Obama continuance of it was this absolutely indefensible permitting of discrimination by religious recipients of tax dollars," he said.
Some of those who favored maintaining that hiring rule were concerned when he signed a 2014 executive order providing sexual orientation and gender identity protections to LGBT employees of companies that do federal government work.
"They make it more murky because here are categories that overlap significantly with religion," said Stanley Carlson-Thies, senior director of the Institutional Religious Freedom Alliance. "So where is the line that can be drawn on that?"
Obama's support of reproductive rights brought out his fiercest critics on the religious right.
Family Research Council President Tony Perkins wrote in December that with half of U.S. states permitting elective abortion as part of the Affordable Care Act, it is "failing millions of pro-life Americans who don't want their taxes subsidizing insurance that covers the brutal killing of innocent unborn babies."
Republican nominee Mitt Romney, who Obama defeated in 2012, accused the president of starting a "war on religion" with the ACA's contraception mandate, which has prompted some 100 lawsuits by religious opponents.
On gay marriage, Obama cited his faith as he shifted his position to ultimately supporting it. "(I)t's also the golden rule, you know? Treat others the way you'd want to be treated," he told ABC News.
The transition was hailed by religious progressives but posed a dilemma for others, including many in the black church community.
African-American clergy praised the expansion of health care to the uninsured as well as the My Brother's Keeper initiative, which provided mentors for many black and Latino boys.
But "there was heartache in many corners" over the president's switch on same-sex marriages, said McKenzie, whose AME Church does not sanction them.
On Islam, Lynn of Americans United credits Obama for distinguishing between most Muslims and terrorists who claim to be defending the faith.
"I think that his efforts to make it clear that you cannot blame an entire religion — Islam — for the acts of some people who at least claim an affiliation with that — those are very powerful statements," he said.
Despite talking about his belief in the birth, crucifixion and resurrection of Jesus at prayer breakfasts, Obama couldn't seem to shake the notion in some Americans' minds that he was a Muslim. As recently as 2015, more than a quarter of U.S. residents — and 43 percent of Republicans — surveyed said they thought he was.
Wear, an evangelical Christian who worked in the faith-based office, said he and other White House staffers at times fielded emails — even one about rumors that the president was holding Muslim prayers on the South Lawn — from people questioning the president's faith.
But, as in the case of his Charleston eulogy, when the president chose to speak about his faith, those were remarks people remembered — and wished his opponents had noticed.
"I always thought, boy, if certain critics of the president would just hear what the president said without knowing who it was, they would say I wonder if this is so-and-so preacher that I really admire," said Carlson-Thies, referring to Obama's words at Easter prayer breakfasts the president hosted at the White House.
Infrequent churchgoing also prompted questions.
Wear, who early on scoped out possible churches for the first family to join, said the decision not to have a Washington congregational home prevented an ongoing "logistical nightmare" for any church that might have been chosen.
"Folks take pictures and are Snapchatting while the first family's trying to take Communion," he said, recalling a visit to a historically black Baptist church in Washington where tourists lined up at metal detectors and displaced stalwart members used to attending each Sunday.
Over the course of his presidency, Obama welcomed religious figures to the White House. He took counsel from spiritual advisers from his first faith-based office director, Joshua DuBois, to Florida megachurch pastor Joel Hunter, and found private worship through the chapel and the chaplain at the Camp David presidential retreat.
On inclusiveness, he was the first president to include "non-believers" in an inaugural address, to light the diya, an oil lamp that symbolizes good overcoming evil during the Hindu holiday of Diwali, and to issue a statement on Vesak, a day honoring Buddha.
And despite the hiring rule and the debate over Obamacare's handling of abortion coverage, legal expert Douglas Laycock said the president's administration mostly worked to lift up religion's place in society.
At last year's meeting of the Religion News Association, he cited examples such as the Justice Department siding with the town of Greece, N.Y., whose sectarian prayers were affirmed by the Supreme Court, as well as supporting churches in zoning battles and prisoners' rights cases.
"They've been right on religion and right on religious liberty more often than they have been wrong," said Laycock, of the University of Virginia School of Law. "And however you characterize the scorecard, it is nothing like a war on religion."