On the Friday before Argentina’s primaries, markets finished the trading day on an optimistic note. Highly regarded polls put President Mauricio Macri and his main opponent, Alberto Fernández, within striking distance, allowing the government to downplay the risk of a serious loss that would raise questions about Mr. Macri’s re-election in the October presidential election.

But as the results trickled in on Sunday evening, markets were quickly disabused of their optimism.

Voters in the primary, known as the PASO, overwhelmingly rejected Mr. Macri in favor of Mr. Fernández and his running mate, former President Cristina Fernández de Kirchner. In the end, Mr. Macri only won in the most strident strongholds of anti-Peronism: Córdoba province, and the City of Buenos Aires.

Worse still, Mr. Macri’s Juntos por el Cambio’s star candidate, Buenos Aires Governor María Eugenia Vidal, was trounced by Ms. Fernández de Kirchner’s controversial former Finance Minister, Axel Kicillof.

In retrospect, the government’s optimism and the market’s hopes were premised on both flawed polling and wishful thinking unanchored by past election experiences worldwide: The belief Mr. Macri could be competitive in a country with a misery index (inflation + unemployment) among the highest in the world simply defied common sense.

Nevertheless, the primary result sent shockwaves through Argentina’s financial markets and politics.

The market’s mood on Monday was nothing short of panic. The country’s stock market saw the world’s largest single day decline since 1989. The peso, already buffeted by a year of devaluations, saw its value decline by almost 38 percent against the dollar, before recovering and ending the day down 17 percent. Argentina’s country risk shot up by 68 percent, to the highest level since 2009.

How did it come to this?

When Argentines narrowly elected Mr. Macri in late 2015, it was as much a vote to rejectkirchernismo as a vote for a change in the country’s statist economic management and divisive populism.

Mr. Macri offered major changes, promising voters normalcy in Argentina’s relations with the world; stronger democratic institutions; the rule of law; lower poverty; less government intervention in the economy; the lifting of capital controls; as well as tax and spending cuts.

As it turned out, fulfilling some of these promises proved difficult.

A celebrity president

On foreign policy, Mr. Macri exceeded expectations.

He was welcomed with open arms at international fora like the G-20 and the World Economic Forum in Davos. Though he lacked a majority in congress, he persuaded lawmakers to approve a settlement with holdout bondholders whose litigation had denied Argentina access to international credit markets for a decade.

He built friendly relationships with both the United States and China, despite increasing tensions between Washington and Beijing. He proved adept at managing temperamental counterparts, including Donald Trump and Jair Bolsonaro. He was at the forefront of regional efforts to condemn Venezuela’s dictator, Nicolás Maduro. Finally, he played apivotal role in negotiating the historic Mercosur-EU free trade deal done.

Unfortunately for Mr. Macri, voters do not vote based on foreign policy issues, but rather, as they say in Argentina, “votan con el bolsillo.”

Stalled reformer

Under Mr. Macri, Argentina’s economic performance was less notable than its diplomacy. From early on, he was determined to move slowly as he addressed the country’s chronic overspending so as not to provoke social unrest. He called his steady process of fiscal consolidation and reform gradualismo.

Buoyed by enthusiastic capital markets tempted by a country with low debt levels and a pro-market government, Argentina was able to borrow at low interest rates. Gradualismoseemed like a winning approach, and the government attracted tens of billions of dollars in foreign loans. However, lulled into complacency by cheap credit, Mr. Macri cut spending too slowly.

At the height of Argentina euphoria, in 2017, Argentina sold a now infamous 100-year bond, and Mr. Macri’s party triumphed in the midterms. The economy was growing, inflation was declining and poverty had reached new lows.

Easy come, easy go

But the next year would be nothing short of a nightmare for Mr. Macri.

After his midterm victory, Mr. Macri spent his political capital on a controversial pension reform that was the start of a long decline in his popularity. The reform sparked violent street protests, and ultimately undermined the government’s efforts to pass critical labor reform.

In late 2017, Mr. Macri’s cabinet chief, Marcos Peña, further tarnished Mr. Macri’s reformist image when he appeared to pressure the central bank to lower interest rates, despite the country’s struggles to reduce inflation. Meanwhile, the government was alienating middle class voters by substantially increasing utility prices, as it continued to grapple with the high deficit it inherited from its populist predecessors.

The coup de grâce for gradualismo was the combined effect of Federal Reserve interest rate hikes in the United States last year, and Argentina’s worst drought in decades. Suddenly, Argentina’s main sources of dollars had dried up. Amid a run on the peso, the government turned to the International Monetary Fund – a bête noire for many in Argentina – for a massive loan. Last September, after Argentina had suffered another run on its currency, the IMF bumped up its loan to $56 billion, the highest bailout in the Fund’s history. By the end of the year, the peso had lost half its value.

From reformer to firefighter

The crisis transformed Mr. Macri from a star reformer into a firefighter.

Argentina’s peculiar relationship with the dollar means a peso devaluation is quickly passed onto consumers through price increases. As a result, last year’s currency crises rapidly worsened inflation, and real wages declined by over 10 percent. Lower aggregate demand increased unemployment to over 10 percent, and raised higher poverty to 32 percent in 2018. (Prior to the current crisis, poverty was projected to hit 35 percent this year; now it will likely be worse). But, out of fears of worsening inflation, the government was unwilling to increase salaries.

Political kryptonite

As this year’s election drew near, Mr. Macri hoped voters would credit his skillful diplomacy, reward his performance fighting crime, and punish the Peronists for the last government’s corruption. After all, he could not run on his economic management. And thanks to IMF loan conditions, he could not ramp up public spending, or print pesos, to juice the economy.

Instead, Mr. Macri’s campaign tried to provoke fear of Ms. Fernández de Kirchner to mobilize voters. His allies went so far as to warn that her return to power risked turning Argentina into Venezuela. In an appeal to centrists, Mr. Macri chose a Peronist, Senator Miguel Ángel Pichetto, as his running mate. Mr. Pichetto also tried to frame the election as a referendum on Ms. Fernández de Kirchner’s legacy: “Two options are available: the consolidation of a democratic model, and authoritarianism.”

But as it turned out, James Carville’s famous dictum, “it’s the economy, stupid,” applies to Argentina too. Especially in the middle of a deep recession.

In Sunday’s PASO, it is now clear, voters sought to punish Mr. Macri for the faltering economy and the widespread pain of budget cuts. Little else mattered.