RIO DE JANEIRO — A motorcade of black vehicles approached Brazil’s presidential palace on Thursday afternoon and then, surprisingly, stopped. To the delight of a crowd gathered under the afternoon sun, out of one of the cars stepped President Jair Bolsonaro.

About two dozen selfie-seekers swarmed the president, who smiled and posed for photos. It was one of the impromptu meet-and-greets that Mr. Bolsonaro has become known for during his campaign for re-election.

Then the cheerful vibe broke. One man in the crowd began shouting, demanding answers about one of Mr. Bolsonaro’s policies. Mr. Bolsonaro got back into his vehicle.