The Spanish parliament has backed a 15bn-euro ($18.4bn; £13bn) austerity package by one vote as the country strives to cut its budget deficit.
The vote saw 169 in favour of the Socialist government's austerity plan and 168 against, with 13 abstentions.
Spain announced the austerity package earlier this month. It includes wage cuts of 5% or more for civil servants and slashes public investment plans.
Spain hopes to rein in its deficit and ease fears of a Greek-style crisis.
A parliamentary defeat would have been a blow to the Socialist government of Prime Minister Jose Luis Rodriguez Zapatero.
Spain's programme is intended to reduce a deficit of 11% of GDP to 6% by 2011.
"The result is calming for the markets because a vote against would have been very worrying," said Jose Luis Martinez, a strategist at Citigroup.
"But the small margin is worrying considering what Spain is facing."
'Painful but inevitable'
Many Spaniards fear the effect the cuts will have on the economy, where the unemployment rate exceeds 20% - twice the eurozone average.
The country moved out of recession in the first quarter of this year, with growth of 0.1%.
The European Union has been anxious to see more fragile European economies, including Spain, Portugal and Greece, impose tougher austerity measures.
Before the vote, finance minister Elena Salgado had asked politicians to vote in favour, saying the measures were "painful but inevitable".