MADRID—Spain’s robust economic expansion is defying concerns that a political impasse, now in its ninth month with no end in sight, would tarnish one of Europe’s economic bright spots.

But the pillars that have sustained Spain’s recovery from recession are showing signs of strain, and economists expect growth to slow in 2017—in part because political uncertainty is putting a damper on some kinds of investment.

The Spanish economy grew 0.8% in the second quarter driven by consumer spending and exports, the country’s statistics agency said Thursday. The uptick is in line with first-quarter growth and better than the 0.7% the agency had predicted in July.

The eurozone’s fourth-largest economy is on track to expand around 3% this year, outpacing the International Monetary Fund’s projections for France, Germany and the U.S.

Spain has been without a full-fledged government since December. Doubts about who will form the next one have persisted since the divided parliament elected that month failed to install a prime minister and was dissolved. A new parliament, elected in June, is also deadlocked among four major parties, none close to a majority.