Obama, standing near Giffords and relatives of other shooting victims, said at the White House public opinion was strongly behind expanded background checks. Despite that, opponents of the legislation were "worried that the gun lobby would spend a lot of money" at the next election, he said.
"So all in all this was a pretty shameful day for Washington," he added.
The day's key test concerned the background checks, designed to prevent criminals and the seriously mentally ill from purchasing firearms. Under current law, checks are required only when guns are purchased from federally licensed firearms dealers. The proposal by Manchin and Toomey called for extending the requirement to other sales at gun shows and on the Internet.
On the vote, Democratic Sens. Mark Begich of Alaska and Max Baucus of Montana joined Pryor and Heitkamp in voting against the proposal. Senate Majority Leader Harry Reid, a supporter of the plan, switched his vote to the prevailing "no" side to permit him to call for a revote in the future.
Begich, Pryor and Baucus are all seeking re-election next year. In an indication of the intensity of the feelings on the issue, the Progressive Change Campaign Committee, a liberal group, swiftly announced it would run ads contrasting their votes with polls showing overwhelming popular support for gun curbs.
Among Republicans, Sens. Susan Collins of Maine, Mark Kirk of Illinois, John McCain of Arizona and Toomey sided with Democrats.
Numerous polls in recent months have shown support for enhanced gun control measures, including background checks, though it may be weakening.
An Associated Press-GfK poll this month showed that 49 percent of Americans support stricter gun laws, down from 58 percent in January. In that recent survey, 38 percent said they want the laws to remain the same and 10 percent want them eased.