This gives Mariano Rajoy considerable breathing space until 2019, as if he fails to get the necessary agreements for next year's budget - due to be negotiated in the autumn -- the constitution allows him to simply renew the previous spending plan.
Presented in March after a long delay, the budget boosts social spending and moves away from the austerity that marked years of crisis in a bid to win opposition support, but Rajoy has nevertheless struggled to get a majority.
Over the weekend, though, his government won the support of a lawmaker from the Nueva Canarias party in the Canary Islands - the last needed to get a majority of 176 lawmakers to pass the budget through in a vote this week.
After the vote, the text is due to be validated mid-June by the Senate, where Rajoy's conservative Popular Party (PP) has a majority, after which it will finally be adopted eight months later than usual.
Spain went through a difficult political year in 2016 as two inconclusive general elections left the country without a fully-functioning government for 10 months.
But at the end of October, Rajoy, whose PP came first in both elections but without a majority, took power again thanks to his rival Socialists who abstained in the obligatory parliamentary vote that sees a candidate through to the premiership.
But he is now ruling at the head of a minority government, a far cry from his first election in 2011 when the PP got an absolute majority.
Adding to this, the Socialists have now re-elected their former, ousted chief Pedro Sanchez as their leader, who has promised to make things difficult for the PP.
As such, Rajoy was forced to battle to earn the support of other parties for the budget.
The centre-right Ciudadanos party pledged its support in exchange for some €4 billion ($4.5 billion) in social spending, while the PNV Basque nationalist party demanded more rail investment and a tax reform in its northern region.
The budget is the first without major cutbacks since Spain was plunged into an economic crisis in 2008, throwing millions out of work.
But with an increase in social spending, there are doubts whether Spain will manage to lower its public deficit to 3.1 percent of economic output this year as planned, and as demanded by the European Union.
By Adrien Vicente / AFP