A Republican-backed measure to derail the Iran nuclear agreement was blocked in the U.S. Senate on Thursday, in a major foreign policy victory for Democratic President Barack Obama.

The vote was 58-42 against clearing the way for debate of the bill, meaning opponents of the nuclear pact failed to get the 60 votes necessary to advance a resolution of disapproval.

All 42 of the votes not to advance the measure were from Democrats or independents who normally vote with them. Four Democratic senators voted with Republicans to move ahead.

Democrats said that the vote killed efforts in the Republican-controlled Congress to derail the nuclear pact, between six world powers and Tehran. Had opponents of the agreement passed such a resolution, Obama would have been barred from waiving many U.S. sanctions on Iran, a crucial part of the nuclear pact.

But the Senate's Republican majority leader, Mitch McConnell, immediately took steps to clear the way for another Senate vote on the matter. "We'll revisit the issue next week and see if maybe any folks want to change their minds," he said.

U.S. President Barack Obama said in a statement that the vote is a "victory for diplomacy and international security."

"Going forward, we will turn to the critical work of implementing and verifying this deal so that Iran cannot pursue a nuclear weapon," Obama said.

Under a law Obama signed in May, Congress has a 60-day period ending on Sept. 17 to pass a resolution disapproving of the international agreement.

If such a resolution were to pass, and survive Obama's promised veto, it would bar the president from waiving many U.S. sanctions on Tehran, a key component of the nuclear deal.

But there was no sign any votes would change, and Senate Democratic leader Harry Reid bluntly responded, "This matter is over with."

Reid urged McConnell to move on to other legislation, including bills providing long-term highway and transportation funding and urgent legislation to fund the government in the fiscal year beginning Oct. 1 and avoid a government shutdown.

"This is a situation where he's (McConnell) lost the vote and it's a situation where he is just not in touch with reality as it exists," Reid said.

The defeat came despite an intense $40 million lobbying campaign against the agreement, largely by conservative pro-Israel groups.

Although the nuclear deal was reached after two years of negotiations with Iran by the United States, Britain, France, Germany, Russia and China, the government of Israeli Prime Minister Benjamin Netanyahu vociferously opposed the agreement. Netanyahu said the deal demanded too little from Iran in exchange for sanctions relief and would strengthen a country he sees as a threat to Israel's existence.

Hours after the Senate vote, Israeli Ambassador Ron Dermer, who had lobbied dozens of lawmakers, said the deal "makes America and Israel much, much less safe."

Speaking at a Jewish New Year reception in Washington, he said Israel and its U.S. ally would deepen security cooperation in the years ahead despite their differences over Iran diplomacy. But he insisted Israel also had "the power and the will to defend ourselves, a will that no deal and no force on Earth will ever break."

House Republicans vow to fight on

Republican in the House of Representatives meanwhile pushed ahead with legislation critical of the nuclear accord. They raised the possibility of filing suit against Obama over the Iran deal or attaching Iran-related legislation to a bill funding the government.

"This is a bad deal with decades-long consequences for the security of the American people and our allies. And we'll use every tool at our disposal to stop, slow, and delay this agreement from being fully implemented," House Speaker John Boehner told a news conference.

Republicans are already using the Iran deal in campaigning against Democrats in the 2016 election. On Wednesday, Republican presidential candidates Donald Trump and Ted Cruz were among the headliners at a raucous anti-deal rally on the lawn of the U.S. Capitol.

But House Republicans split over how to handle the agreement, after weeks of marching in lockstep in opposition to the nuclear deal, announced on July 14.

This week, as Democrats gathered more than enough votes to protect the nuclear deal, House Republicans came up with their own plan for three Iran-related votes after a rebellion by some of the party's most conservative lawmakers.

On Thursday, House members voted strictly along party lines, with 245 Republicans voting yes and 186 Democrats voting no, to pass a resolution finding that Obama had not complied with terms of the Iran nuclear review act he signed in May.

Some Republicans argued that the 60-day window for reviewing the deal had never opened because Obama had not sent Congress details of what they termed "secret side deals" regarding inspections of Iran's nuclear facilities.

The House was to vote on Friday on two other Iran-related measures, a resolution of approval of the Iran deal that Republicans hoped to defeat by a wide margin, and a separate one that would bar Obama from waiving sanctions.

But none of the three would have a direct impact on the nuclear pact similar to that of a disapproval resolution, a mechanism outlined in the Iran review act.

The House has not scheduled a vote on its own resolution of disapproval. And there are no plans now for the Senate to vote on legislation similar to the three measures being considered in the House.

The 42 members of the Senate Democratic caucus who supported the nuclear deal on Thursday are also far more than the 34 senators whose votes would be needed to sustain an Obama veto.