The miners' march into the capital was the culmination for some of a nearly three-week trek from the remote regions where they eke out a living, and drew heavy sympathy from Spaniards weary of a series of government-imposed measures that have increased taxes, made it easier to fire workers and reduced cherished government services.
Some miners walked from northern and eastern mining regions into Madrid, where they received a hero's welcome by thousands lining La Castellana avenue outside the Industry Ministry building.
The miners detonated deafening fireworks as they marched, then hurled them at the police riot vans guarding the ministry, which oversees the mining industry. Police fired rubber bullets at the ground as a warning, and opened fire on the protesters after they threw more fireworks and rocks and bottles at officers, witnesses said.
Most demonstrators fled to side streets for safety after the violence began, but a police spokeswoman said 22 demonstrators and 10 officers were treated for injuries by emergency workers. Six of the protesters and two of the officers were taken to hospitals, said the spokeswoman, who was unable to provide their conditions and spoke on condition of anonymity because of department policy.
The violent end to Wednesday's protest in Madrid is still a relatively rare event in Spain. While there have been sporadic street clashes at Spanish demonstrations as Europe's financial crisis worsened over the last several years, the country has largely been spared the violence seen in places like bailed-out Greece.
Retired miner Olvidio Gonzalez winced in pain as he lay on a stone bench, a huge, round, bloody welt marking the spot where a rubber bullet hit him.
"We were walking peacefully to get to where the union leaders were speaking and they started to fire indiscriminately," said Gonzalez, 67. "There was no warning."
But protester Santiago Oviedo, 24, a physics masters candidate, said he saw protesters hurling fireworks, bottles, cans and rocks at police outside the ministry and that the protesters threw more objects after officers fired at the ground.
The volleys then fired by officers at protesters sent many running into side streets. Some people were beaten by officers wielding batons, and Oviedo said he saw at least 10 people hit by rubber bullets.
The protest came just hours after Spanish Prime Minister Mariano Rajoy imposed a new sales tax hike and other spending cuts aimed at eliminating €65 billion ($79.85 billion) in spending from the nation's budget over the next two and a half years. The country already has the highest unemployment rate in the 17-nation eurozone — nearly 25 per cent — and is in its second recession in three years.
The miners, wearing hardhats and carrying walking sticks, had snaked along the avenue under a hot sun to protest a 63 per cent cut in subsidies to mining companies imposed by the government as it tries to reduce a bloated deficit.
Miner David Menendez said he has worked in the pits for 10 years and fears losing his job in an economy that offers few prospects for anything else.
"I'm here to defend my work," Menendez said, wearing a miner's hard hat and a black T-shirt that said "Proud to be a Miner."
As for the new austerity cuts, the 30-year-old Menendez accused Rajoy of "committing crimes against the economy and killing it. It's just cuts and more cuts."
The new spending reductions include a new wage cut for government workers and members of Parliament and a fresh wave of closures at state-owned companies. As miners approached the ministry building, some encouraged riot police to join them in the demonstration since officers will make less money.
Joining the miners were Madrid residents who related to the miners' plight because they also have suffered under the austerity cuts brought on by Europe's financial crisis and a Spanish property boom that went bust, prompting the country to seek a bailout of its hurting banks from a €100 billion lifeline approved by the eurozone nations.
Marcher Pepi Garcia said she makes €900 ($1,105) per month but is supporting her 35-year-old daughter and 21-year-old son still living in her home because they are unemployed and have never landed jobs lasting more than six months.
"I'm not here just to show solidarity," said Garcia, a 52-year-old hotel waitress. "We have to protest to stop the madness that is happening in Spain."
While Spain is expected to ask for tens of billions of euros to prop up banks that lent too freely during the property boom, she said her children "can't even think about getting their own apartments or starting families" because of the country's miserable economy.
Alejandro Casal, 28, an Airbus factory worker marching with fellow union members, said the miners' protest "isn't only their struggle. It's a struggle for the working class."
"The people need to be here on the street to say 'Enough is enough,'" he said.
Retired miner Gonzalez said he blamed Rajoy for Spain's deepening problems, including unemployment for two of his four grown children.
"He promised he wouldn't touch our health care or education or raise taxes. The reality is everything is falling apart," Gonzalez said. "What's happening here is like a dictatorship, it's unjust and I am so angry."
Daniel Woolls contributed to this report from Madrid.