Spain’s recent elections produced one of the most lopsided results since the country’s return of democracy in 1975.

With a 186-seat parliamentary majority and more than 44% of the vote, the conservative Popular Party managed its best performance ever, while the ruling Socialists suffered their worst defeat. If incoming President Mariano Rajoy doesn’t deliver his country from economic catastrophe, it won’t be because he lacks political support.

Of all the troubled countries in Europe, Spain is the most significant. Given their relatively small sizes, Greece, Ireland and Portugal—the countries already temporarily “rescued” by the European Union—do not represent the core of the euro zone. And Italy, whose troubles are comparable to Spain’s, has a long history of getting into trouble and muddling through. So Italy’s problems raise few eyebrows.

But Spain was supposed to be different. Spain was the great success story of modern Europe, a nation that leapt from political isolation, economic backwardness and social repression to modernity. Its current plight, therefore, is more consequential.

Spain’s problems, frankly, should have been anticipated. Somewhere during that splendid leap forward, many Spaniards lost the connection between effort and reward. They forgot that working, saving and investing real assets is the path to success. They decided to reap the rewards without renewing the effort, not realizing that sooner or later prosperity would stop.

A housing bubble, which hit Spain worse than any other country, was the tipping point. Compounding the problem were its onerous welfare state, rigid labor rules, regulations that dissuaded people from starting businesses and high taxes on middle-class earners who don’t benefit from tax loopholes accessible to higher earners.

Once the crisis hit, 150,000 companies went bankrupt and unemployment topped 21%. Among young people, the percentage was twice as high.

Then came the Socialist government’s efforts to rescue various industries and protect workers, while government revenue dropped precipitously. The result was a huge increase in the government debt, which now equals about 360% of GDP—more than triple that of the U.S.

This is the poisoned present that President-elect Rajoy will inherit from the departing Socialists at the end of December. Rajoy has promised major reforms on taxation, labor laws and financial regulation to ease the stifling business climate—in the hope that such measures will boost investor and consumer confidence.

If Spain had its own currency, rather than the euro, Rajoy would have to devalue the peseta until it found its real level, thereby making exports more competitive. But given that Spain, like most of Europe, is wedded to the euro, the burden of correcting the mess will fall heavily on wage earners, pensioners and consumers, who will see their buying power eroded by higher prices and stagnant wages. It is unavoidable.

Government benefits of all sorts will have to be cut. That also is unavoidable. Generous welfare-state socialism and a healthy economy cannot coexist ad infinitum. Despite Rajoy’s mandate, there is no guarantee that Spanish society will tolerate the difficult medicine that’s required.

Portugal, where austerity measures have set off demonstrations against another recently elected government, suggests what may be in store.

Hanging over Rajoy is also the question of what will happen with Europe as a whole. The most likely scenario is a massive rescue effort by the European Central Bank and indirect transfers from richer countries to those that have lived profligately beyond their means. Aside from the cost that such a decision will have for Europe down the road, it will not help Spain solve its problem—an institutional and cultural bias against sustainable prosperity.

By all indications, Rajoy understands what is needed. It is as yet unclear, given his coy and prudent communications strategy, whether he will do what he knows needs to be done.