President Obama signed a bill that he says will save hundreds of thousands of teacher and other public workers from unemployment.

Obama signed the measure into law just hours after the House passed it in a special one-day session during what would normally be the lawmakers' summer break.

The $26 billion bill would protect 300,000 teachers, police and others from election-year layoffs. Obama and Democrats said quick action was necessary before children return to classrooms minus teachers laid off because of budgetary crises in states that have been hard-hit by the recession.

Republicans called the bill a giveaway to teachers unions and an example of wasteful Washington spending.

The bill would be paid for mainly by closing a tax loophole used by multinational corporations and reducing food stamp benefits for the poor. It passed mainly along party lines by a vote of 247-161.

Representatives scattered around the country and world for the August break were summoned back to Washington for the one-day session as Democrats stressed the need to act before children return to classrooms missing teachers laid off because of budgetary crises in the states.

Republicans saw it differently, calling the bill a giveaway to teachers' unions and another example of profligate Washington spending that Democrats would pay for in the coming election.

The Senate narrowly passed the measure last Thursday, after the House had begun its summer break, necessitating the special session.

The legislation provides $10 billion to school districts to rehire laid-off teachers or ensure that more teachers won't be let go before the new school year begins. The Education Department estimates that that could save 160,000 jobs.

Another $16 billion would extend for six months increased Medicaid payments to the states. That would free up money for states to meet other budget priorities, including keeping more than 150,000 police officers and other public workers on the payroll.

Some three-fifths of states have already factored in the federal money in drawing up their budgets for the current fiscal year. The National Governors Association, in a letter to congressional leaders, said the states' estimated budget shortfall for the 2010-12 period is $116 billion, and the extended Medicaid payments are "the best way to help states bridge the gap between their worst fiscal year and the beginning of recovery."

Not all governors were on board. Mississippi Republican Gov. Haley Barbour said in a statement that the bill would force his state to rewrite its current year budget and it would have to spend $50 million to $100 million to get the additional $98 million in education grants.

The $26 billion package is small compared to previous efforts to right the flailing economy through federal spending. But with the election approaching, the political stakes were high.

"Teachers, nurses and cops should not be used as pawns in a cynical political game" resulting from "the Democratic majority's failure to govern responsibly," said Rep. David Dreier, R-Calif.

"Where do the bailouts end?" asked Republican leader John Boehner of Ohio. "Are we going to bail out states next year and the year after that, too? At some point we've got to say, 'Enough is enough."'

Democratic Rep. Jay Inslee said his state of Washington would get funds to keep 3,000 teachers. Republicans, he charged, "think those billions of dollars for those corporate loopholes is simply more important than almost 3,000 teachers and classrooms in the state of Washington."

Rep. Jim McDermott, D-Calif., said Republicans ignore the fact that the bill is paid for and does not add to the deficit. "They want to do everything in their power to make certain that President Obama can't get this country going again. I think in November they are going to find it was a dumb policy."

The means of paying for the bill, a result of difficult negotiations in the Senate, were also contentious.

Republicans objected to raising some $10 billion by raising taxes on some U.S.-based multinational companies. Advocates for the poor were protesting a provision to accelerate the phasing out of an increase in food stamp payments implemented in last year's economic recovery bill. Under the measure, payments would return to pre-stimulus rates in 2014, saving almost $12 billion.

James Weill, president of the Food Research and Action Center, said that would be cutting benefits for some 40 million people now receiving food stamps. "Those families will be hungrier and less able to buy healthy diets," he said.

Weill's group estimated that a family of four that may now receive about $464 a month in food stamps stood to lose about $59 if the reductions take place. Democrats gave assurances that they would look for other ways to pay for the bill before the payment cuts go into effect in four years.

"The cutbacks in food stamps in the bill are plain wrong," said House Appropriations Committee Chairman David Obey, D-Wis.

American Federation of State, County and Municipal Employees President Gerald McEntee rejected GOP arguments that the Democrats' primary purpose with the legislation was to reward their friends in organized labor. "We're in tough shape out there with these incredible holes in these state budgets. To the American people it's tremendously important and will give a little lift to the economy," he said of the legislation.

The House on Tuesday also passed a $600 million measure to boost security on the U.S.-Mexican border by hiring more enforcement officers and making greater use of unmanned surveillance drones. That bill still has to go back to the Senate.