Brazil is having its Donald Trump moment.

On Sunday, far-right candidate Jair Bolsonaro won Brazil's presidential election. Bolsonaro is like a Brazilian Trump, but worse. He takes all of President Trump's worst aspects and cranks them up another few notches. He holds women, immigrants, and indigenous and gay Brazilians in open contempt, and has repeatedly and openly called for violence against opponents. He wants to liberalize gun laws, free up police to shoot criminals, and unshackle agribusiness to decimate Brazil's rainforest. He's even implied that he'd support returning Brazil's young democracy to military rule.

But Bolsonaro is something else as well: an example of how the perils of capitalism can foster political extremism.

Economic historian Karl Polanyi described this well. Free-market ideology makes a series of demands upon human society: fiscal discipline, tight money, liberalized trade, free international capital, and so on. All of it is subject to self-correcting market signals. Plenty of individuals profit by this system. But others are decimated. All too many livelihoods are upended and destroyed, whole towns ripped apart. Unemployment, poverty, and insecurity are permanent, grinding constants for many people.

Eventually, when enough people have it bad enough, this system generates a crisis. But "society" isn't some rational, thinking entity. Its reactions can be healthy, like when America enacted the New Deal, and once again subjugated markets to democracy and human needs. But if that sort of interventionist economic reform is prevented, you can get a poisonously unhealthy reaction. We're seeing it now, with the aftershocks of economic earthquakes still rattling the West by allowing Trump, Brexit, and xenophobic nationalist parties across Europe to rise from the rubble. When capitalism fails too many people, and the government fails to help them, they often turn to right-wing populism — and sometimes outright fascism.

This brings us back to Bolsonaro.

Brazil enjoyed a big run of economic success in recent decades. But it remains an emerging power, and its economy is deeply entangled with the U.S. dollar. That makes it harder for Brazilian policymakers to run monetary policy and counteract inflation. While Brazil has some capital controls, it remains vulnerable to capricious international investors, who may pump it full of money and then yank that cash out again just as quickly. Brazil also relies on commodity exports and its big trade surplus. If there are aggregate demand collapses elsewhere in the world — like, say, Chinese growth slows — Brazil suffers as well.

Several of these factors came together to drive up Brazilian inflation, and then set off a brutal economic recession in 2015 and 2016. Unemployment hit 14 percent at the peak of the crisis, as GDP contracted by 8 percent.

At the same time, the reigning left-wing Workers' Party, which had shepherded Brazil through many of its boom years, was overrun by scandal. Former President Luiz Inacio Lula da Silva is serving a prison sentence. His successor, President Dilma Vana Rousseff, was impeached in 2016. There seems to be widespread agreement that Da Silva is so beloved he could've won this election if he'd been allowed to run. But Brazil's frustration with the Workers' Party as a whole remains massive.

Dealing with Brazil's crisis fell to Rousseff’s successor, Michel Temer, of the Brazilian Democratic Movement Party. And he responded with the standard neoliberal playbook.

Interest rates were jacked up, while Temer pushed through a crushing suite of austerity measures. Brazil's Swiss cheese tax code was left largely unreformed, while government spending on public investment and aid to the poor suffered the bulk of the cuts. Studies suggest child mortality in Brazil has increased due to these policies, which were widely loathed by voters.

It all came to naught: While inflation and interest rates have fallen, Brazil's economy is showing meager turnaround at best. Unemployment is still around 12 percent, and by the time of the election Temer's popularity was an astoundingly low 2 percent.

Bolsonaro's opponent, Fernando Haddad, said he would scuttle Temer's labor and spending "reforms," prevent privatizations of the country's major state-owned enterprises, and reinvest in Brazil's economy. But he also tried to emphasize his orthodox positions on inflation and deficits. And then there was the Workers' Party's ruined reputation.

It must also be mentioned that crime in Brazil is a serious problem, peaking at a record 63,880 murders last year. And Bolsonaro shamelessly capitalized on the problem with brutal law-and-order rhetoric.

At any rate, it shouldn't be surprising that Brazil's economic decay and elite failure gave rise to right-wing revanchism. If leaders around the world want to stop what Trump and Bolsonaro represent, they must do better at protecting their citizens from the ravages of capitalism.

Unfortunately, Brazil's business leaders ultimately decided to back Bolsonaro's campaign. This, too, is a lesson: in just how much the beneficiaries of free-market capitalism will sacrifice to keep the whole enterprise going just a little longer. At the end of the day, they decided they'd rather elect a fascist than risk even Haddad's moderate left-wing turn in economic policy.