The charismatic leaders who ride these resentments to power are almost always false prophets,
promising security and prosperity even as they erode their foundations.
The danger they pose to new democracies is greater than in more deeply rooted ones.
Mr Trump is constrained by Congress, an independent judiciary,
a free press and a bureaucracy with a long tradition of following the law.
Mr López Obrador, by contrast, will govern a country that has been democratic only since 2000,
and where corruption is widespread and growing worse.
The next president's main job should be to reinforce the institutions that underpin a modern economy, democracy and above all the rule of law.
The risk with Mr López Obrador, who will be the first non-technocratically minded president in 36 years,
is that he will do precisely the opposite.
Mexican technocracy has had its successes.
Orthodox economic policies have ensured relatively steady if unspectacular growth since the 1990s.
Thanks to the North American FreeTrade Agreement (NAFTA) with the United States and Canada, which took effect in 1994,
Mexico is the world’s fourth-biggest exporter of motor vehicles.
The outgoing president, Enrique Pena Nieto, opened energy and telecoms to competition
and is trying to impose higher standards on a failing school system.
Alas, progress has been slower than politicians promised and is uneven.
Mexico's south, where a quarter of the population lives,
has ox-drawn ploughs rather than assembly lines.
By Mexico's own measure, nearly 44% of its citizens are poor.
The main source of Mexicans'discontent is not inequality
but crime and corruption, which have run riot under Mr Pena.
The murder rate has broken a record set in 2011.
The ruling party has seen countless scandals.
It emerged that Mr Pena's wife's $7m home had belonged to a government contractor.
In an ordinary election, Mexicans would ditch Mr Pena's Institutional Revolutionary Party
and turn back to the conservative National Action Party.
But after its last crime-ridden years in power, from 2006 to 2012, they are fed up with that, too.
They want change, which Mr López Obrador certainly offers.