Joined by trade unionists in the capital, the miners rallied at the climax of a 44-day protest against a 60% cut in coal subsidies which they say will force mines to close and put many out of work.
Carlos Marcos, 41, a miner for 23 years, said: "We're only asking that they cut 10% instead of 60%.
"If they don't pay attention to us, we'll be back – with dynamite."
Some of the miners had walked 250 miles from the north of Spain. Many waved wooden walking sticks, while others threw firecrackers.
Jose Ramon Pelaz, 38, said: "We have to take to the streets to fight because the time is coming when we won't have enough to eat."
Centre-right premier Mr Rajoy outlined further austerity measures in parliament to save £51 billion (€65bn), including a three-point rise in VAT – going back on a promise not to do so during the election campaign.
He also announced budget cuts for government ministries in a speech interrupted by jeers and boos from the opposition.
Mr Rajoy told Parliament: "These measures are not pleasant, but they are necessary.
"Our public spending exceeds our income by tens of billions of euros.
"We are living in a crucial moment that will determine the future of our families, our youth, our social welfare and all our hopes. That is the reality. We have to get out of this mess and we have to do it as soon as possible."
He also announced new indirect taxes on energy, plans to privatise ports, airports and rail assets, and a reversal of property tax breaks that his party had restored last December.
However, he did not touch pensions – keeping one election promise – and said the tax burden was being shifted from direct taxes on labour and income to taxation on consumption.
The miners gathered in Madrid's Puerta del Sol – the centre point of Spain – in the early hours, their path illuminated by lights on their helmets. They were met by thousands of Spaniards who turned out in sympathy.
Some of the miners who have marched through northern Spain since June hail from Asturias, a traditional centre of leftist militancy.
With five years of economic stagnation and recession, unemployment at 24.4% and tax revenue falling, Spain is struggling to meet tough deficit-cutting targets agreed with the European Union.
The high deficit and weak banks, which will receive up to £78bn in European aid, are now at the centre of the eurozone's debt crisis as investors are concerned that Spain could join Greece, Portugal and Ireland in needing a sovereign bailout.
Madrid's borrowing costs have soared in recent months, with the yield on the 10-year Government bond breaching the 7% level regarded as unsustainable in the long run. Yesterday, that yield fell to 6.81%.
The EU agreed on Tuesday to give Spain more time, until 2014 instead of 2013, to bring the public deficit down to 3% of gross domestic product and relaxed this year's goal to 6.3%. However, a European Commission document said even that easier target would be difficult to reach.
With the latest measures, Mr Rajoy overhauled his previous budget plan, in which the central government and 17 autonomous regions had put in place some €48bn (£38bn) in savings for 2012, insufficient to bring the deficit into line.
Contextual targeting label: