Democracy, as we’ve found out the past few years, can be a fragile thing.

That’s not to say that reactionaries have started seizing power from popularly elected governments in coups or revolutions. The truth is both less dramatic and more insidious than that. No, it’s that reactionaries have started winning power themselves as the leaders of popularly elected governments. Democracies, in other words, are electing people who aren’t really democrats. At least not in the small-D sense of the word by respecting things such as a free press, an independent judiciary and minority rights.

And sometimes all it takes is an ill-timed recession or corruption scandal for this to happen. Just ask Brazil, which is still reeling from both and, as a result, elected the once-fringe, far-right figure Jair Bolsanaro as its next president.

It’s actually a pretty simple story. Brazil’s economy has been going through a fairly standard emerging-markets crisis. It started in the early 2000s when the global commodity boom sent Brazil’s growth up so much that households began borrowing a lot more, and foreign money came pouring in to try to get a piece of the pie. This was good while it lasted, but the problem is that it didn’t last.

Brazil’s Bolsonaro tells Israeli newspaper he plans to move embassy to Jerusalem

By 2014, all this had gone into reverse: Commodities had collapsed, consumers had slowed down their borrowing, and, in part because of the end of the U.S. Federal Reserve’s quantitative easing program, money that had gone to Brazil in search of higher returns now returned to the United States.

The good news, insofar as there was any, was that Brazil’s central bank raised interest rates enough to keep its currency from falling too far — and its dollar debts from getting too hard to pay back — while its government built up enough of a rainy-day fund to cover all that. It did what was necessary to avoid the kind of vicious circle that Turkey is flirting with now, where a weaker currency increases your debt burdens and increased debt burdens weaken your currency even more.

This came at a cost, though. It always does. Higher interest rates hit Brazil when its economy was already faltering because of the effects of lower commodity prices and sent it into a deep recession. In fact, it was the worst one on record, going all the way back to the 1930s. Brazil’s unemployment rate jumped from a little more than 6 percent in 2014 to a little less than 14 percent in 2017.

Who is Jair Bolsonaro, Brazil’s next president?

In normal times, this kind of economic failure would just be a political one for the party in power. It would lose the next election to its main rival. But these were not normal times. A pervasive corruption scandal at the state-owned oil company implicated not only the center-left Workers Party, but also the center-right Democratic Movement party. That meant there was an opening for someone to argue that it was time to throw all the bums out — and with a vigor that wasn’t necessarily compatible with democratic niceties.

That’s how Bolsonaro — who praised Brazil’s earlier military dictatorship, dedicated his vote to impeach former president Dilma Rousseff to the colonel who had tortured her, spoke of his desire to get rid of democracy altogether, told a female lawmaker that she was too ugly to rape, said it would be better to be dead than gay and denigrated the country’s black minority — managed to win a majority in the second round of presidential voting.

The same sort of thing happened in Hungary. Various corruption scandals took down its mainstream right-wing parties, then the financial crisis took down its mainstream left-wing one. At that point, Viktor Orban’s Fidesz party was able to win enough votes that it could rig all the future elections in its favor. The result is that Hungary is now less a multiparty democracy and more a one-party state.

It’s a reminder that even if history ever does “end” — in the sense that liberal democracy is ascendant — that it’s always just a few bad decisions and few bad quarters of GDP growth from coming back.