WASHINGTON — A bill that would have greatly tightened screening procedures on refugees from Syria and Iraq failed on a procedural vote in the Senate on Wednesday, saving President Obama from another vexing veto scenario on an issue that has divided the country.

While the measure passed overwhelmingly in the House late last year, Senate Democrats had vowed to stop it, and the matter quickly became enmeshed in presidential politics, presaging what is all but certain to be a contentious and protracted proxy battle for the White House fought in Congress this year.

“Over and over again, Republicans remain committed to pledging loyalty to the divisive platform they have built for Donald Trump,” said Senator Harry Reid of Nevada, the Democratic leader, tying the issue of the refugee screening to Mr. Trump’s proposal to bar Muslims from entering the United States.

Three Republican senators running for president left the campaign trail briefly and returned to vote on the measure, an outgrowth of the terrorist attacks in Paris and elsewhere last year and of increasing unease among American voters over the nation’s security.

The senators — Marco Rubio of Florida, who has missed scores of votes over the last several months; Ted Cruz of Texas; and Rand Paul of Kentucky — all voted to move forward with the bill, along with the rest of their fellow Republicans.

The bill, which the House passed in November, 289 to 137, with nearly 50 Democrats supporting it, would have required that the director of the F.B.I., the secretary of the Department of Homeland Security and the director of national intelligence confirm that each applicant from Syria and Iraq poses no threat, which the White House denounced last year as “untenable.”

In some ways, the refugee issue, attached to a large spending bill in December, was obviated by another measure that made changes to the so-called visa waiver program, which had permitted citizens of 38 countries to travel to the United States without a visa.

Under that new measure, with certain narrow exceptions, the United States now bars residents of Iraq, Syria, Iran and Sudan and foreigners who have traveled to those countries since March 2011 from participation in the program.

Just a few months ago, Republicans were highly motivated to halt the refugee program. On Wednesday, they seemed resigned to move on.

Republicans quickly pivoted to a coming bipartisan bill that would promote energy efficiency; expedite applications to export liquefied natural gas; and improve the nation’s electric grid, among other provisions. “We have a great opportunity to work together,” said Senator John Barrasso, Republican of Wyoming, barely mentioning the refugee bill.

Democrats, after mocking Republicans for rejecting their last-minute amendment effort with, as Senator Dick Durbin, Democrat of Illinois, put it, the fear of “scalded cats,” made only a halfhearted effort to press the issue on the floor.

Mr. Reid offered to come up with Democratic support to debate the bill if Republicans would agree to guarantee votes on four amendments, one of which was specifically designed to embarrass Republicans.

That measure would have officially denounced “Donald Trump’s reprehensible proposal to impose a religious test on admission into the United States,” Mr. Reid said. Another would have prevented people on the no-fly list from being able to buy firearms, which had already failed on the Senate floor. “We’ll not allow Republicans to hijack the Senate floor to play politics with our national security,” Mr. Reid said.

Republicans rejected the Democrats’ assertion that the bill was unfair to refugees, and argued that it was needed because war-torn Syria did not have proper record-keeping on its citizens for vetting.

Saying that supporters of the bill were “motivated by love for their families and communities,” Senator Mitch McConnell, Republican of Kentucky and the majority leader, said, “I understand that the political pressure to oppose this balanced bill may be intense, but it’s also intensely shortsighted.”

Resisting commitments to specific amendments, Mr. McConnell offered a broader amendment process to get the bill moving, which Democrats rejected.

Democrats are almost certain to find opportunities to vote on measures related to the policy positions of Mr. Trump and perhaps of other Republican candidates this year, largely targeting vulnerable Republican senators up for re-election. Republicans have vowed to return to the favor — “What’s good for the goose is good for the gander,” Mr. McConnell said last week.

At the same time, Republicans also looked to other ways to embarrass or annoy the White House. Mr. McConnell immediately moved to set up a vote to override Mr. Obama’s recent veto of a congressional resolution that would have overturned his administration’s regulations on clean water. The House is expected to do the same, an effort that is likely to be successful. Senate Democrats will almost certainly block that effort Thursday, and members of both parties will then race to the airport in hopes of beating an expected snowstorm in Washington.

Republicans will also almost certainly seek to address immigration issues this year once again. Some members are eager to vote on a measure that would impose a five-year mandatory sentence on immigrants who are deported and return to the United States illegally.

Americans are increasingly concerned about national security, and Mr. Obama’s policies in Syria have bedeviled his presidency. In a poll conducted this month by The New York Times and CBS News, Americans disapproved of Obama’s handling of overall immigration policy by 55 percent to 37 percent.

In a similar poll in December, those surveyed were roughly split over whether the United States should allow any refugees from Syria into the United States.

That strong public sentiment has forced Democrats to take the bill quite seriously. At the same time, some Republican senators up for re-election in swing states have been reluctant to take up the issue.

“By blocking this measure, Senate Democrats are making it that much harder for us to keep Americans safe,” said House Speaker Paul D. Ryan of Wisconsin in a statement Wednesday. “Their vote is irresponsible in a time of grave threats. Even the administration’s top law enforcement officials say there are gaps in our refugee program that terrorists can exploit.”