Senate Democrats on Thursday easily defeated Republicans' attempt to derail President Obama's Iran deal -- a somewhat unlikely victory given growing public opposition to it and many Democrats' skepticism over the details.

"This vote is a victory for diplomacy, for American national security and for the safety and security of the world," Obama said in a statement.

Here are the details of what happened, politically speaking:

The Senate voted Thursday afternoon 58-42 to shut down debate and move to a vote on a resolution that would have disapproved of the historic nuclear deal that the U.S. and five other nations reached with Iran in July.

Republicans needed 60 votes to allow that vote on the resolution, which if it became law would have weakened the international deal -- at least symbolically.

The vote failed despite the fact a majority of senators oppose the Iran deal. The Republican-controlled House of Representatives, where the majority rules, is expected to pass the resolution disapproving of it. So if Democrats had failed Thursday, the resolution likely would have also passed the House, forcing Obama to break out his veto pen to keep the deal intact. But even then, the deal would have been safe. In August, Democrats secured enough votes (34) to uphold that veto if the Republican Congress attempted to override it with votes of two-thirds in each chamber.

Senate Majority Leader Mitch McConnell (R-Ky.) said he'd try again to open debate on the bill next week.

Basically, there were a lot of ifs here. But Democrats successfully built firewalls to all those ifs, which is why after Thursday's vote, Senate Minority Leader Harry Reid (D-Nev.) could confidently say on the Senate floor:

"Today's outcome is clear, decisive and final. There is now no doubt whatsoever that the United States Congress will allow this historic agreement to proceed."

First, Democrats got to the 34 votes required to uphold a veto -- securing the deal. Then, they got to 41 supporters, which left open the possibility that the resolution wouldn't even come to a vote in the Senate and would never require Obama's veto pen. But heading into this week, it was not clear that all 42 supporters of the deal would vote against moving forward with an actual vote on the resolution. Some expressed significant concerns and might have wanted to go on-the-record in the final vote. If even two supporters allowed for that vote -- indications were Sen. Chris Coons (D-Del.), for instance, could have crossed over on the preliminary vote -- it would have happened.

And yet, all 42 stuck together and stopped the vote from happening.

And that's impressive. Polls largely show the Iran deal is unpopular with Americans, having hemorrhaged support since it was announced in July and losing even more as lawmakers spent their five weeks back home reviewing it. If you're a Senate Democrat up for reelection in 2016, Thursday's vote to limit debate on the Iran deal was not an easy one. 

[The Iran deal is unpopular. Here's how that could hurt Senate Democrats]

As the final Democratic senators skeptical of the deal came out in support of it in September, they immediately faced primary challengers -- and some threats of general-election challengers.

But Reid kept his Democrats in line, sparing Obama from being forced to thwart the will of Congress on one of his biggest diplomatic and political legacy items. It was an impressive victory for Obama, but Thursday's procedural vote was perhaps an even-more-impressive feat for Senate Democratic leaders. 

More on the Iran deal:

Republicans are coming up short on the Iran deal. And they might be okay with that

Why the Iran deal is so huge for Obama's legacy

How to argue about the Iran deal