On a barren ridge high above the Mediterranean, a couple dozen tall white wind turbines spin in a breeze.

Wind provides about 18 percent of Spain’s electricity these days, and out-performed every other source of power in Spain last winter, according to Miquel Cabre, who heads a regional wind-power association.

Cabre says the industry should be celebrating, but it isn’t.

“I look out at these new machines and I am a happy man,” Cabre said. “But I’m frustrated, too. Because a few years ago people used to call us wind energy advocates crazy. Today, that skepticism may be gone, but so is the money.”

Same goes for solar. For nearly a decade, the Spanish government paid people handsomely to produce renewable energy, guaranteeing huge subsidized returns for up to 25 years. The goal was to attract investors, bring costs down and help cut the country’s dependence on imported fossil fuels.

It worked, at first. The money came pouring in by the billions and renewable production surged to nearly a quarter of the country’s energy last year. Everyone, it seemed — from farmers to mom and pop investors to international investment funds — wanted a piece of the pie.

In his office outside Tortosa, Spain, financial advisor Francisco del Rio shows off an aerial photo of the 40 acre solar farm he convinced 40 people to invest in back in 2008. The cluster of huge black panels dwarfs a nearby village. Del Rio says the investors were supposed to earn about a 10 percent yearly return on the project, but now, he says, they stand to lose their shirts.

“We’re not talking about people with lots of money,” del Rio said. “These are folks who needed the return.”

So what went wrong?

Economist Mike Rosenberg says the answer is simple: Spain ran out of money after the housing and banking crashes four years ago.

“And these subsidies, which were thought to be very generous, were seen as no longer affordable,” he said.

The Spanish government has reduced the subsidy for green energy 13 times since 2010, for big and small investors alike. Most investors say they figured the initial support was too generous, so they expected reductions over time.

But earlier this year, the Spanish government did something no one saw coming.

At a small office by the rail lines in the port of Tarragona, solar entrepreneur Mark Segura recalls the day he read the single word that he says sank the future of green energy here: retroactivity. The government announced that its subsidies would shrink — not just in the future, but going back to the beginning of the program.

In effect, people would lose some of the money they’d already earned.

That 10 percent you thought you’d banked over the last five years? You’ll actually have to give some of that back.

Segura says one reason investors bet on green energy was the guaranteed return.

“But then the government’s plan to cut profits after the fact created instant fear in the market,” he said.

Fear, and lawsuits — an estimated 30 pending against the Spanish government for changing the rules in the middle of the game. Many of them are being brought by foreign firms who’ve invested about $25 billion.

That money won’t necessarily be lost, but the government cuts could wipe out any profits, and that means Spain’s once-booming renewables sector may be dead in its tracks.

Anne Mieke Van der Werf, who manages a Danish energy investment fund with renewable energy holdings in Spain, says new investments in Spain are out of the question.

“If I compare Spain to position in other markets, then I find Spain is not stable enough,” she said.

With foreign money scared off, Spain has already lost an estimated 50,000 jobs in solar and wind energy, from design to construction to maintenance.

Now, refugees from the business are everywhere here.

Software engineer Roberto Gonzalez had launched a start-up company making systems to help solar panels track the sun. At his new job he wears an apron.

He opened a bar in Madrid.

“We launched in 2008, and the contracts were to start in 2010,” he said, serving a plate of potato salad. “We were on the point of signing with Siemens and a dozen other firms, but they all backed off.”

Now, with subsidies shrinking again and again, Gonzalez says he has zero hopes for a renewable industry comeback in Spain. And the promise of green energy eventually replacing fossil fuels here has likely been punted into the distant future.