By Sonya Dowsett

MADRID (Reuters) - Residential construction is coming back to life in Spain eight years after a property crash, with foreign investment pouring into developments in Madrid and Barcelona, and a jump in building permits pointing to more growth to come.

Half a million newly-built homes remain empty after the mania that peaked in 2007, largely on urban fringes and in remoter areas where people don't want to live.

But demand for properties ranging from luxury apartments to homes for the middle classes is rebounding in leading cities and industrially-strong regions such as the Basque Country, showing how Spain's economic recovery is on course despite political paralysis after two inconclusive general elections.

Construction and real estate accounted for more than a third of the nearly 22 billion euros ($24 billion) of foreign investment in Spain in 2015, Economy Ministry data shows.

While overall activity remains a small fraction of peak levels, funds spent on residential construction last year were more than 80 times greater than in 2014.

"The market has fired up precisely because players have come from overseas," said Ernesto Tarazona, partner at property consultancy Knight Frank. "There are some local investors left, but not many."

Foreign funds desperate for a return on their investments at a time of ultra-low interest rates have flocked to Spain as the 2008 crisis has knocked around 40 percent off property prices.

According to real estate portal Idealista, rental yields increased to 6.1 percent in the second quarter, five times the return on a 10-year government bond.

Spain still has no new government, seven months and two elections after Prime Minister Mariano Rajoy lost his parliamentary majority, with leading parties so far failing to agree on a coalition.

But this doesn't seem to be discouraging property investors. Madrid ranked fourth in a 2016 league of European cities which PWC compiles, based on a survey of investors' and developers' views on which property markets offer the best prospects.

The Spanish capital ranked ninth globally in an EY survey which asked real estate executives where they plan to invest in the next few months.

Investments vary widely - from buying blocks of rented apartments to packets of mortgage debt and banks' property management units.

Private equity funds have become the country's new developers, looking to make profit on residential building given Spain's fourth year of economic recovery and a lack of suitable property in areas that are in demand. Property consultant CBRE predicts annual demand of 180,000 units over the next 10 years.

At the top end, Rockspring is funding a development of a 19th century building on Madrid's upmarket shopping boulevard Serrano, where the nine apartments range in price from under 2 million euros ($2.2 million) to 8 million.

"By the time we had published the brochure, we had already sold 60 percent of the apartments," said Eduardo de Roda, Associate Director at Rockspring Iberia.

GRAPHIC - Licenses and sales for new-build housing in Spain http://tmsnrt.rs/29Jxdtn

LATIN AMERICAN DEMAND FOR LUXURY

Also at the high end of the market, U.S. private equity firm Pimco and local property fund Grupo Lar <LRES.MC> are investing in a development of around 40 units in central Madrid with a swimming pool and spa, expected to sell from around 3 million euros each.

At around 10,000 euros per square meter, these prices are easily on a par with pre-crisis levels. But in international terms they are modest at perhaps one tenth of properties in the best districts of London and a quarter of those in Paris.

In contrast to Spain's boom years, many prospective buyers at the high end of the market in Madrid are wealthy Latin Americans seeking a relatively secure investment, estate agents and developers say.

Britain's vote to leave the European Union, which has battered UK property funds, may have a knock-on effect on the second-home market on the Spanish coast where the pound, which has dived since the June 23 referendum, can buy less. However, developers expect Brexit to have a limited impact in cities such as Madrid and Barcelona.

Away from the luxury sector, the economic recovery and growth in job creation have led to demand for newly-built city housing.

Nationwide, the number of licenses awarded to build new homes increased by 57 percent year-on-year in the first three months of 2016 - the biggest first quarter annual jump since 2009 and a strong indicator of new building projects to come.

This burst of activity is banking on demand that has naturally built up during the recovery but not been satisfied in recent years when construction levels were at rock bottom.

Monthly sales of newly built homes registered a yearly increase in April for the first time in two years, but remain at just a fifth of pre-crisis levels.

The contribution of construction to Spain's economy has halved since the boom years to around 5 percent with the loss of more than 1.5 million jobs.

'AN INDUSTRIAL MODEL'

One developer backed by U.S. private equity firm Lone Star is buying up land on a massive scale for developments in areas with demand including Madrid, Barcelona and the Basque Country, priced between 100,000 euros and 250,000 euros.

Lone Star bought the property management arm of unlisted Spanish bank Kutxabank and about half the real estate assets on its books in December 2014 for 930 million euros.

The real estate management platform, Neinor, has more than doubled its land bank since then to around 900,000 square meters by investing around 500 million euros in land that already has the permits required for construction, says Neinor Chief Executive Juan Velayos.

"We want to lead the residential developer market in Spain, and to do that we need a big land bank," he said. "In 2015 there was hardly any competition and we could buy a large part of the suitable land available in Spain. Now there's more competition and less land."

Neinor has implemented a U.S.-style home-building operation, tightly focused on margins and costs at every phase. Buyers reserve homes off-plan with a small deposit. Once up to 30 percent of apartments are 'pre-sold', building starts. Keys are handed over to the new owners around two years later.

Neinor already has 2,200 homes, or more than 35 developments, being marketed around Spain and more than 1,000 'pre-sold'. It aims to deliver around 3,000 homes per year, with developer margins of around 15 percent.

"We are aiming for an industrial model," said Velayos.

(Editing by Julien Toyer and David Stamp)