And while Mr. Trump’s aides said he has little in common politically with the anarchists and anti-globalism protesters in the streets of this gritty port city, they said the president intuitively understood their rage in a way that few other leaders at the summit could.