The topic of race produced the rawest moments of Thursday’s Democratic debate, highlighting fault lines that divide the party even as President Trump’s challengers seek to present an inclusive image in contrast with his history of racially divisive rhetoric.

In a white mayor’s regret for a police-involved shooting of a black man, a biracial senator’s emotional chastising of a white former vice president and his pained response, the debate underscored how racial issues are shaping a primary contest that features a diverse field of candidates.

Those dynamics were on display when Pete Buttigieg, the 37-year-old mayor of South Bend, Ind., was asked why his city’s predominantly white police force did not reflect the city’s diversity.

Buttigieg responded that he “couldn’t get it done,” then expressed unvarnished remorse for the death of Eric Logan, a 54-year-old black man who died in a recent encounter with a South Bend police officer.

“My community is in anguish right now,” he said, as the debate hall grew quiet. “It’s a mess, and we’re hurting.”

Buttigieg noted that the officer’s body camera was not turned on, leaving no video of the incident. He said he could have “walked you through all of the things that we have done as a community, all of the steps that we took, from bias training to de-escalation,” to prevent racial bias in policing.

“But it didn’t save the life of Eric Logan. And when I look into his mother’s eyes, I have to face the fact that nothing that I say will bring him back,” Buttigieg said.

The comments marked a shift in focus on the second day of the first Democratic debate, during which 10 candidates faced off in wide-ranging discussions about immigration, health care and climate change.

Buttigieg’s initial response to the shooting had disappointed activists and family members of the victim, who criticized the mayor as not showing compassion or offering them information. The controversy underscored tensions between the young, white mayor and the black community in South Bend, where 40 percent of African Americans live below the poverty line.

Rep. Eric Swalwell (D-Calif.) challenged Buttigieg on how he should hold police accountable for Logan’s death.

“If the camera wasn’t on and that was the policy, you should fire the chief,” he said across the stage in Miami.

Buttigieg replied that the incident “will be investigated, and there will be accountability for the officer involved.”

“But you’re the mayor. You should fire the chief — if that’s the policy and someone died,” Swalwell said.

As other candidates chimed in, Sen. Kamala D. Harris (D-Calif.), noted she was the only black person on the stage and asked to speak “on the issue of race.”

In one of the evening’s defining exchanges, Harris challenged former vice president Joe Biden’s recent comments expressing pride in his past work with segregationist senators and his opposition to busing as a way to integrate schools.

“I do not believe you are a racist, and I agree with you when you commit yourself to the importance of finding common ground. But I also believe that it is personal, and it was hurtful to hear you talk about the reputations of two United States senators who built their reputations and career on the segregation of race in this country,” she said.

Harris described her own experience being bused to school as a young girl in Berkeley, Calif., arguing that the federal government should have done more to intervene, since integration in her community was still taking place “two decades after Brown v. Board of Education.”

“Do you agree today that you were wrong to oppose busing in America then? Do you agree?” she asked Biden, turning toward him.

“I did not oppose busing in America. What I opposed is busing ordered by the Department of Education. That is what I opposed,” Biden said, defending the pace of integration in Berkeley as a “local decision.”

“That is where the federal government must step in,” Harris said, drawing applause and cheers. “That’s why we have the Voting Rights Act and the Civil Rights Act. . . . There are moments in history where states fail to preserve the civil rights of all people.”

Biden responded that he had fought for civil rights legislation throughout his nearly four decades in the Senate.

“It’s a mischaracterization of my position across the board,” he said. “I did not praise racists. That is not true, number one. Number two, if we want to have this campaign litigated on who supports civil rights and whether I did or not, I am happy to do that.”

Biden added that he was once a public defender.

“I didn’t become a prosecutor,” he said, an implicit shot at Harris, who served as district attorney of San Francisco and attorney general of California.

“I’m the guy that extended the Voting Rights Act for 25 years,” Biden said. “We got to the place where we got 98 out of 98 votes in the United States Senate doing it.”

He soon cut himself off: “Anyway, my time’s up, I’m sorry.”

Throughout the night, the candidates contended with questions of racial injustice.

Calling for reparations in redress of slavery, Marianne Williamson, a self-help author, identified what she described as “deep, deep, deep realms of racial injustice, both in our criminal justice system and in our economic system.”

“I do not believe that the average American is a racist, but the average American is woefully undereducated about the history of race in the United States,” she said.

Pressed on his own views about diversity, Sen. Bernie Sanders (I-Vt.) said it was important but should not be the only consideration as primary voters cast their ballots.

“We need a party that is diverse, but we need a party that has the guts to stand up to the powerful special interests who have so much power over the economic and political life of this country,” he said.