MADRID — Millions of Spaniards stayed off the job Thursday to protest new labor laws that allow companies to opt out of collective bargaining pacts, reduce wages and fire workers more easily.

The general strike stalled public transportation and shut factories and schools across the country. Angry confrontations erupted between hordes of protesters and riot police officers, but no major violence was reported.

It was the first such large-scale labor action against the policies of conservative Prime Minister Mariano Rajoy and the strongest public rebuke yet of his austerity measures. In office for just three months, Rajoy has focused on cutting spending to shrink the country’s yawning budget deficit and to meet European Union rules on fiscal discipline, which previous governments routinely flouted.

Rajoy is to unveil his 2012 budget Friday, including up to $50 billion in cuts,Spain’sharshest yet. EU officials and financial markets are eager for a commitment to frugality by Madrid, afraid that the long-running euro debt crisis might otherwise flare up badly again and engulf the Eurozone’s fourth-largest economy.

But Spaniards are holding their breath for possibly punishing cuts in welfare, education and healthcare, hallmarks of the European welfare state that are now in danger across the continent.

“Food, fuel — all the prices are going up,” said Carlos Rodriguez, 50, an elevator mechanic on strike. “Now with this labor reform, they can reduce our pay and increase our hours. We don’t agree with that.”

Spain has already enacted rounds of budget cuts to tame its deficit, but overspending by regional governments forced Rajoy to announce recently that Madrid would miss the deficit target it agreed to with the EU. Since then, Spain’s borrowing costs have flirted with modest but worrisome increases, reinvigorating fear that the country might have to seek a costly international bailout, after similar rescues of Greece, Ireland and Portugal.

Finance ministers of the Eurozone’s 17 countries, which use the euro currency, are scheduled to meet in the coming days to discuss beefing up the region’s bailout resources. But many analysts say that the slightly less than $1-trillion total being proposed is insufficient to reassure investors that the big economies of Spain and Italy can be saved from a default if borrowing on the open market becomes too expensive.

Even the Netherlands, which has loudly preached the virtues of fiscal restraint to its southern European neighbors, is now struggling with the need for major austerity measures. The Dutch coalition government has been locked in negotiations for days over proposed budget cuts and is teetering dangerously close to collapse.

Hundreds of thousands of protesters packed town squares across Spain on Thursday. In Madrid’s central Puerta del Sol plaza, hundreds staged a sit-in outside a department store and cried “Shame!” at police manning barricades that allowed store employees to cross picket lines. “Without the uniform, you are one of us!” they yelled.

Red union banners waved above the crowded square, along with homemade posters depicting scissors with a red line through them, to protest the budget cuts.

Spain’s two largest unions organized the strike in response to labor reforms approved by lawmakers this month. Backers say the sweeping changes are needed to modernize an antiquated labor system in which older, tenured workers have jobs for life and younger people are left struggling to get a foot on the employment ladder.

But critics say the reforms unfairly favor employers and will lead to a rise in the unemployment rate. Nearly one in four members of the Spanish workforce is jobless, and the rate is nearly 50% for people younger than 25.

“If you lose your job, especially if you’re over 40 or 45, it’s very hard to find another one,” said David Le More, a spokesman for UGT, one of the organizing unions. “So people fear a lot that with these new conditions, they’ll get fired, and new people with lower-earning contracts will get their jobs.”

Union leaders have set a deadline of May 1 for the government to amend its labor reforms or face further unrest.

Before the strike, polls showed that 30% of Spanish workers planned to take part, but authorities did not issue crowd estimates. Late Thursday, unions claimed participation of 77% of all workers.

Most public transportation systems were running on reduced schedules. Garbage collection was suspended, and trash piled up on many city streets.

Frayer is a special correspondent. Times staff writer Henry Chu in London contributed to this report.