Thousands gathered in Neptune plaza, a few meters from El Prado museum in central Madrid, where they formed a human chain around parliament, surrounded by barricades, police trucks and more than 1,500 police in riot gear.
Police fired rubber bullets and beat protestors with truncheons, first as protestors were trying to tear down barriers and later to clear the square. The police said at least 22 people had been arrested and at least 32 injured, including four policemen.
As lawmakers started to leave the parliament late Tuesday in official cars or by foot, a few hundred people were still demonstrating in front of the building. Most dispersed shortly afterwards.
The protest, promoted over the Internet by different activist groups, was younger and more rowdy than recent marches called by labour unions. Protestors said they were fed up with cuts to public salaries and health and education.
"My annual salary has dropped by €8,000 and if it falls much further I won't be able to make ends meet," said Luis Rodriguez, 36, a firefighter who joined the protest. He said he was considering leaving Spain to find a better quality of life.
Demonstrators also said they were angry that the state has poured funds into crumbling banks while it is cutting social benefits.
With this year's budget deficit target looking untenable, the conservative government is now looking at such things as cuts in inflation-linked pensions, taxes on stock transactions, "green taxes" on emissions or eliminating tax breaks.
The 2013 budget is the second conservative Prime Minister Mariano Rajoy has had to pass since he took office in December. Spain must persuade its European partners that it can cut the budget shortfall by more than €60 billion by 2014.
Rajoy has already passed spending cuts and tax hikes worth slightly more than that over the next two years, but half-year figures show the 2012 deficit target slipping from view as tax income forecasts will not be hit due to economic contraction.
He said earlier this month the 2013 budget would cut spending further in all areas of government apart from pensions and borrowing costs.
Spain is at the centre of the eurozone debt crisis on concerns the government cannot control its finances and those of highly indebted regions, bitten by a second recession since 2009 which has put one in four workers out of a job.
On the regional front, Catalonia, which generates about 20% of the national output, announced on Tuesday it would hold early elections on 25 November after its call for more tax autonomy was rejected last week by Rajoy.
Political uncertainty in cash-strapped Catalonia, along with an announcement from southern region Andalucia it might seek a €4.9 billion credit line from the central government, will pile more pressure on Madrid to seek European aid.
Rajoy is holding back from applying for help, which would activate a European Central Bank bond-buying programme and bring down Spain's punishing debt premiums.