The confrontations highlighted Mr. Obama’s struggle to respond to the Black Lives Matter movement, a diffuse group unlike established civil rights organizations that have deep relationships at the White House and on Capitol Hill.

Mr. Obama first invited Black Lives Matter activists to the White House in 2014 after unrest in Ferguson, Mo., following the killing of an unarmed black man, Michael Brown, by a white police officer. White House officials said at the time that the activists had grievances but few constructive suggestions. Mr. Obama has prodded them to focus on solutions.

“The goal of protest isn’t just to protest for the sake of protesting,” he said at last week’s town-hall-style meeting. “The goal of protest is to then get the attention of decision-makers and sit down and say, ‘Here’s what we would like to see,’ and have a negotiation, which over time can actually lead to improvements in the system.”

The president, his advisers say, identifies with the protesters’ cause — a former community organizer, he spoke at last week’s meeting about his experiences of being discriminated against by police officers and others — but as the person who appoints the nation’s top law enforcement official, he is equally sensitive to police concerns.

“His empathy isn’t only with the movement, it’s also with the enormous challenge that law enforcement officers have,” said Valerie Jarrett, Mr. Obama’s senior adviser. “He can feel both perspectives because he is of both perspectives.”

In his meeting with Mr. Mckesson at the White House last week — a four-hour session that included activists and law enforcement and elected officials — Mr. Obama said, according to accounts from several in attendance, that it would not be appropriate for him to visit Ferguson or other cities where police killings of black men have occurred. Visits with the families in those places, he said, could be seen as siding with them in open investigations.

The president thanked Mr. Mckesson pointedly for what he called a long “to-do list,” and he added that his willingness to take hours out of his packed schedule should indicate his seriousness about addressing problems of race and policing.