The president recognized Ms. Evers-Williams, whose endorsement of the museum boosted its credibility, calling her “his incredible widow,” and thanking her for carrying on “Medgar’s legacy.” He also thanked the people of Mississippi, a state, he said, “where I’ve had great success.”

Speaking later to a polite and enthusiastic crowd of about 1,800 under a chilly bright blue sky, Ms. Evers-Williams said: “Going through the museum of my history, I wept because I felt the blows. I felt the bullets. I felt the tears. I felt the cries. But I also sensed the hope.”

Presidents are often called on to reflect upon the country’s darker chapters and to inspire a better future. In 2015, President Barack Obama marched across the Edmund Pettus Bridge in Selma, Ala., where African-Americans were beaten during “Bloody Sunday” in 1965. Mr. Obama, the nation’s first black president, declared in a speech that despite the progress, the “nation’s racial history still casts its long shadow upon us.”

Mr. Obama occasionally grappled publicly with the country’s racial divisions, especially in the wake of the violence that erupted after police shootings of unarmed black men. Mr. Obama’s earlier comment about a white police officer’s “stupid” arrest of a black Harvard professor led to a “beer summit” in which the three men discussed the state of race relations in the country.

For Mr. Trump, race has been a more inflammatory topic. His campaign was rooted in an appeal to disaffected white voters, and his comments about Mexicans and Muslims have generated accusations of racism. His efforts to impose a travel ban on people from mostly Muslim countries have been declared racist by several federal judges, though the Supreme Court has now allowed a third version of the ban to take effect.

In August, Mr. Trump was widely condemned for saying that “both sides” were to blame for the violence that erupted in Charlottesville when white supremacists gathered to protest the city’s removal of a Confederate statue.

Invited by Mississippi’s Republican governor, Phil Bryant, Mr. Trump attended the event on Saturday in the hopes of helping to unify a country that has been struggling to repair its lingering racial schisms. But if he thought his presence here would prove to be a bridge, he may have been mistaken.