The razor-thin majority piled pressure on Socialist Prime Minister José Luis Rodríguez Zapatero, who has been forced to ditch his party's traditional alliances in pushing through spending cuts and labor reforms as markets fret Spain could suffer a similar crisis to Greece but on a larger scale.
The vote was won by 169 parliament members, all from the Socialist Party, voting in favour, and 168 against, from the opposition European People's Party-affiliated Popular Party, the Basque nationalist party, Esquerra Republicana de Catalunya, Izquierda Unida, Iniciativa per Catalunya Verds, Bloque Nacionalista Galego, Nafarroa Bai and Unión Progreso y Democracia.
The Popular Party even made sure one of its deputies was brought to the session in an ambulance.
There were 13 abstentions, from representatives of Convergència i Unió (CiU), Coalición Canaria and Unión del Pueblo Navarro.
It was the abstention of 10 members of CiU, a Catalan nationalist party regarded as conservative or centrist, which saved the plan, EurActiv Spain writes.
CiU parliamentary leader Josep Antoni Duran i Lleida told parliament he did not want to plunge Spain into an immediate Greek-style crisis by blocking the austerity measures, but called on Zapatero to call elections early next year.
"The problem is you and your government," Duran i Lleida told Zapatero, adding that his party would vote against the 2011 budget bill towards the end of the year.
The prime minister called off a scheduled trip to Brazil on Thursday, as an end-May deadline loomed for an agreement with unions and business on wide-ranging labour reforms - a key policy demand by international markets.
Unions met on Thursday and warned that they would call a general strike if the government goes ahead with changes to labour market rules without their consent, saying there were still big differences with business on the reform.
They said agreement may not come before the end-May deadline set by the government. A regular Europe-wide meeting of unions is scheduled to take place in Brussels on 1 June.
"The government can set whatever deadlines it wants, we work at our own pace," the head of the CCOO union, Ignacio Fernandez Toxo, told journalists.
Defeat for the budget would make it much more difficult for Zapatero, lagging the Popular Party in opinion polls, to stay in power.
"This law is improvised, insufficient and unjust," PP leader Mariano Rajoy told parliament.
(EurActiv with Reuters and EurActiv Spain.)