By Richard Cowan and Susan Cornwell

WASHINGTON (Reuters) - Another attempt at gun control faltered in the U.S. Congress on Thursday despite outrage at the Orlando massacre, as a proposed ban on firearms sales to people being monitored for links to terrorism barely avoided being killed in the Senate.

In a procedural vote, the Senate narrowly rejected an attempt to scrap the plan by Republican Senator Susan Collins to prevent guns getting into the hands of people on two U.S. government terrorism watch lists.

But the proposal looked short of the support it would need to advance through the chamber, and Republican leaders said the Senate would switch from debating gun control to other matters until at least after the July 4 holiday.

It was the latest setback for proponents of gun restrictions who have been thwarted for years on Capitol Hill by gun rights defenders and the National Rifle Association.

Frequent efforts at gun control have failed despite anger at mass shootings like the killings at an elementary school in Newtown, Connecticut, in 2012 and in San Bernardino, California, last year.

“Eventually this problem will get addressed again one of two ways: We find a breakthrough, which I will seek, or there will be another terrorist attack which will bring us right back to this issue. I hope we can do it without another terrorist attack,” said Senator Lindsey Graham, a Republican who supported Collins.

A few hours earlier, Democratic lawmakers ended a sit-in protest in the House of Representatives over guns.

Fueled by Chinese food and pizzas, dozens of them stayed on the House floor all night, at times bursting into the civil rights anthem "We Shall Overcome" before giving up their protest after 25 hours.   

"It's not a struggle that lasts for one day, or one week, or one month, or one year," said Representative John Lewis, a Democrat from Georgia and a key figure in the civil rights protests of the 1960s. "We're going to win the struggle," said Lewis, who led the House sit-in.

    Dramatic protests by legislators are rare in the U.S. Capitol and the sit-in underscored how sensitive the gun control issue became after this month's Florida attack, the deadliest mass shooting in modern U.S. history.

Opinion polls show Americans are increasingly in favor of more restrictions on guns in a country with more than 310 million weapons, about one for every citizen.

ORLANDO ATTACK

After a gunman pledging allegiance to Islamic State fatally shot 49 people at a gay nightclub in Orlando, some senators had seen resistance to gun restrictions softening because the issue had partly become one of national security.

But Collins' measure received only 52 votes in the 100-seat Senate test vote, short of the 60 votes that would be needed for approval in future Senate procedural votes.

While her plan could be revived next month, it is unclear if she has the momentum to overcome pro-gun rights forces in Congress who argue that gun control measures in Congress have been too restrictive and trample on the constitutional right to bear arms. Four other gun control measures failed earlier this week.

Collins, a Maine lawmaker, wants to forbid gun sales to anyone on the U.S. government's "No Fly List" for terrorism suspects or the "Selectee List" of people who receive extra security screening at airports.

Despite the lack of legislation, the gun debate has stirred passions. The House Democrats' sit-in brought an outpouring of grass-roots activity.

Jennifer Hoppe, deputy director of Moms Demand Action for Gun Sense in America, said that in less than 24 hours from Wednesday, about 130,000 calls were made from supporters of gun control to members of Congress.

First lady Michelle Obama backed the House Democrats' protest.

"We have grieved for too many children and wept for too many families after shootings. Chicago. Tucson. Newtown. Charleston. Orlando. #Enough," she wrote on Twitter on Thursday.

The Democrats were seeking votes on legislation to expand background checks for gun purchases, as well as measures to curb the sale of weapons to people on government watch lists

Republicans allied with the NRA gun rights group say that while they want to combat terrorism, they represent constituents who believe firmly in the constitutional right to bear arms.

"It’s a tough issue. For people like myself, who come from a hunting and fishing state, it’s pretty hard,” said Senator Orrin Hatch, a conservative Utah Republican who voted against Collins.

(Additional reporting by Richard Cowan, Timothy Ahmann, Timothy Gardner and Eric Walsh, Doina Chiacu; Writing by Alistair Bell; Editing by Bill Trott and Peter Cooney)