MADRID—Spain will pump €19 billion ($24 billion) into troubled lender Bankia SA, the bank said Friday, effectively nationalizing the country's third-largest bank in a dramatic effort to assuage concerns about the stability of its financial sector.

Worries about Spain's banks, which are saddled with billions in toxic real-estate loans, have heightened in recent weeks as Greece's political crisis has intensified and investors contemplate the knock-on effects of a potential Greek exit from the euro.

Sentiments...