MADRID—Spain has been quietly tapping the country's richest piggy bank, the Social Security Reserve Fund, as a buyer of last resort for Spanish government bonds, raising questions about the fund's role as guarantor of future pension payouts.

Now the scarcely noticed borrowing spree, carried out amid a prolonged economic crisis, is about to end, because there is little left to take. At least 90% of the €65 billion ($85.7 billion) fund has been invested in increasingly risky Spanish debt, according to official figures, and the government has begun withdrawing cash for emergency payments.

Although the trend has drawn little public attention or controversy, it has become a matter of concern for the relatively few independent financial analysts who study the fund, which is used to guarantee future payments of pensions. They say the government will soon have one less recourse to finance itself as it faces another year of recession and painful austerity measures to close a big budget deficit.

That pressure, some analysts said, could force Prime Minister Mariano Rajoy's government to seek a rescue this year from the European Union's bailout fund, a politically risky course he seeks to avoid.

In addition, there are worries that Social Security reserves for paying future pensioners are running out much quicker than expected.