LONDON — While the Spanish government was able to sell all the bonds it wanted to on Thursday, it mostly sold to the usual buyers: Spain’s increasingly fragile banks.

And so, as Madrid tries to come up with the money to bail out its banks, its main lenders are increasingly becoming many of those same institutions.

If it sounds like the most vicious of circles, it is.

Economists warn that over the long term, Spain will have trouble meeting its substantial financial requirements until foreign investors return to the market as regular buyers, injecting new money into the system. Until late last year, foreign investors were doing just that. But lately, much of the foreign money has been staying away.

Foreign investors are leery of the high risks involved in holding the debt of a government facing the twin challenges of persistent budget deficits and a banking industry, hobbled by bad real estate loans, that may soon require a bailout costing as much as 100 billion euros, or $126 billion.