ÁNGEL MIRALDA was proud of his 320 solar panels in a field near Benabarre, in northern Spain. They added 56 kilowatts of clean-energy capacity to a country that depended on oil imports. The panels cost €500,000 ($735,000): €150,000 from an early-retirement pay-off from IBM’s Barcelona office, the rest from a bank loan. The government promised a 10% annual return on such projects. That was in 2008. Five years later, after subsidies were cut on July 12th for the third time since 2012, his income is down by 40% and he is struggling to repay the loan. “There is no legal security in Spain,” he complains.

Mr Miralda is the victim of a bungled, overambitious renewables programme. Governments everywhere want to turn green and create environmentally friendly jobs. But as Spain shows, good intentions are not enough. If the policies are wrong, the benefits are wasted, the jobs disappear, the costs remain—and business investors bear the brunt.

In 2007 Spain had just 690 megawatts (MW) of installed capacity of solar photovoltaic (PV) panels. That was the year global PV prices started to fall, thanks to booming production in China. Hoping to stimulate a new green industry, for which sunny Spain seems ideal, the government increased the prices it paid for solar power to 12 times the market price for electricity.

In a sense, it worked spectacularly. According to research by CF Partners, a carbon-trading firm, solar PV capacity rose fivefold in 2008 alone. Another technology for capturing the energy of sunlight, solar thermal, also grew hugely, albeit more slowly because it takes longer to deploy. Its installed capacity rose from 11MW in 2007 to 1,950MW now. Renewable-energy output doubled between 2006 and 2012. At that point, Spain had the fourth-largest such industry in the world.

But costs exploded, too. Subsidies to solar energy rose from €190m in 2007 to €3.5 billion in 2012 (an 18-fold increase). Total subsidies to all renewables reached €8.1 billion in 2012, see chart. Since the government was unwilling to pass the full costs on to consumers, the cumulative tariff deficit (the cost of the system minus revenues from consumers) reached €26 billion, having risen by about €5 billion a year.

This would have been unaffordable at the best of times: €8 billion is almost 1% of GDP. But as the euro crisis overwhelmed Spain’s finances, reform of the renewable-energy bonanza became inevitable. On July 12th the government unveiled its latest cuts. It lopped €2.7 billion off the overall bill, of which €1.4 billion were cuts to subsidies for rewnable energy and €1.3 billion cuts to other revenues of utility companies. That was on top of the €5.6 billion cuts that (reckons Acciona, a construction firm) it has already imposed in 2011-13.