MADRID — Spain on Saturday agreed to accept a bailout for its cash-starved banks as European finance ministers offered an aid package of up to $125 billion.

The humbling request — by a nation of 47 million that sought to fend off the embarrassment of a bailout for months — came as Spain faced mounting international pressure to cave in and ask for cash.

European leaders hope the promise of such a large package, made in an emergency conference call with Spain, will quell rising financial turmoil ahead of elections in Greece next week that they fear could further shake world markets.

The decision made Spain the fourth and largest European country to agree to accept emergency assistance as part of the euro crisis. The aid offered was nearly three times the $46 billion in extra capital the International Monetary Fund (IMF) figured was the minimum the wobbly Spanish banking sector needed.

In recent weeks, investors have demanded higher and higher costs to lend to Spain, and it became clear it would be just too expensive for the country to borrow the money necessary for a bank rescue from the markets.

The announcement of a deal came amid growing fears instability in Spain could drag down an already sputtering world economy. The decision was the culmination of weeks of a contentious back-and-forth between Spain and its would-be creditors in which it was hard to tell how much of Spain’s resistance to financial help was tactical maneuvering for a better deal and how much a refusal to admit the depth of the banking sector’s troubles.

The escalating tension prompted President Obama to push Friday, in unusually explicit terms, for quick European action.

Spain’s Economy Minister Luis de Guindos announced the deal after an emergency conference call with eurozone financial leaders. He said the aid will go to the banking sector only and would not come with new austerity conditions attached for the economy in general, conditions that have been an integral part of bailouts to Portugal, Ireland and Greece.

The Spanish acceptance of aid for its banks is a big embarrassment for Prime Minister Mariano Rajoy, who insisted on May 28 that the banking sector would not need a bailout. He was elected in November, took office in December and walked right into a hurricane.

Spain had fought to avoid the stigma of a bailout and tried to portray the Europeans’ offer as coming with few strings attached.

Indeed, Spanish officials Saturday denied their country was in the same position as Greece, Portugal and Ireland. “What we are asking is financial support, and this has absolutely nothing to do with a full bailout,” de Guindos, the economy minister, said at a news conference in Madrid. He said the assistance “allows us to have an ample safety margin” and “will return trust and confidence to the euro project.”

The exact figure of the bailout has not been decided. De Guindos said the country is waiting until independent audits of the country’s banking sector have been completed before asking for a specific amount. The audits are expected by June 21.

The figure of $125 billion was intended to cover the “estimated capital requirements with an additional safety margin,” the eurozone finance ministers said.

International pressure on Spain to solve its financial problems has grown more urgent in recent weeks. On Thursday, ratings agency Fitch hit Spain with a three-notch downgrade of its credit rating. That left it two levels above junk status. Moody’s Investor Services on Friday warned it could downgrade Spain and other countries in the eurozone.

Spain’s financial problems are not due to Greek-style government overspending. The country’s banks got caught up in the collapse of a real-estate bubble. However, as Spain’s leaders have struggled for a solution to their banking crisis, the country’s borrowing costs have soared close to the level that forced the governments of Greece, Portugal and Ireland to seek rescues. Portugal has received abut $98 billion, Ireland about $106 billion and Greece about $300 billion.

The deal to shore up Spain’s banks is the latest in a marathon crisis that has seen one stopgap solution after another during the past three years. The 11th-hour fixes have always given way to new speculation about the long-term solidity of the currency union.

“It’s a calming signal at a time when calming signals are badly needed,” said Jens Boysen-Hogrefe, an economist at the Kiel Institute for the World Economy. He added that it did not solve the underlying problems of Spain or the eurozone as a whole. “The uncertainty is still high, and bad news can pop up anywhere in the euro area. This is not a final solution.”

The money will be channeled through the Spanish bank-bailout fund, but the Spanish government will be responsible and will have to sign the memorandum of understanding and the conditions that come with it.

Robert Tornabell, banking professor at the Esade business school in Barcelona, said that despite the government’s insistence to the contrary “what has just been agreed is in fact a bailout, just like what had to be done for Ireland because of its banking problems.”

Material from The Associated Press and The Washington Post is included in this report.