President Barack Obama, standing with Vice President Joe Biden, speaks in the East Room of the White House in response to the Iran nuclear deal, July 14, 2015. Andrew Harnik - Pool/Getty Images

WASHINGTON -- President Barack Obama secured one of the largest pieces of his foreign policy legacy by finalizing a deal with Iran. The agreement -- intended to stop access to nuclear weapons by the Iranian government -- will likely be one of the key pieces of foreign policy that he leaves when he departs office in 2017.

“History shows that America must lead not just with our might, but with our principles,” Obama said in announcing the deal. “It shows we are stronger not when we are alone, but when we bring the world together. Today’s announcement marks one more chapter in this pursuit of a safer and more helpful and more hopeful world.”

But it’s a gamble for Obama. The deal can easily be reversed by the next president when he leaves office, causing any hope for a lasting impact to crumble. And if Iran opts to cheat on the deal, the criticism being heaped on the president now from Republicans will be viewed as prophetic instead of partisan.

Obama ran for office as an anti-war president, but has presided over more than six years of continued war. He called for decreasing the size of the military and ending the wars in Iraq and Afghanistan. But instead, his administration has been marked by the rise of drone attacks and continued war in the Middle East. Efforts to reduce American troops in the region have been met with staunch criticism with the rise of the Islamic State group.

President Barack Obama and Vice President Joe Biden walk in the Cross Hall after Obama spoke on the nuclear deal with Iran on July 14, 2015 at the White House in Washington, DC. AFP/Getty Images/Mandel Ngan

Finding a way to strike a peaceful end to the standoff with Iran -- and to a lesser degree Cuba -- could reverse the existing legacy as a wartime president.

And as a lame duck president with no control in Congress, Obama has made foreign policy much of the primary objective of his last two years in office. In recent months, Obama has undertaken an effort to normalize relations with Cuba despite loud objections from Republicans in Congress. And he has mostly ignored the insistence from those same members that he engage with more troops and military strength in the Middle East fight against the Islamic State group.

Foreign policy has long been a domain that Congress has limited ability to influence. The Senate is required to approve treaties, but presidents have long avoided that hurdle by structuring deals as executive agreements instead of treaties. And Congress can limit funding -- like refusing to appropriate money to keep the planned U.S. Embassy in Cuba running. But there are still means for a president to increase diplomatic relations without much cash. Thanks to legislation passed earlier this year, Congress will have little power to block the Iran deal from taking effect.

The praise piled in from Democrats, who described the agreement as landmark and historic and lauded Obama and Secretary of State John Kerry for reaching an accord.

“This is a victory for diplomacy over saber-rattling and could keep the United States from being drawn into another never-ending war in the Middle East,” Sen. Bernie Sanders, D-Vt., a 2016 presidential candidate, said. “I look forward to learning more about the complex details of this agreement to make sure that it is effective and strong.”

Obama Administration - Troop Strength | InsideGov

Sen. Tim Kaine, D-Va., praised the deal as a “solution to peacefully” stop Iran from developing a nuclear weapon. “A nation’s commitment to diplomacy is every bit as important as its commitment to military strength,” Kaine said.

Republicans in debating the deal in Congress are likely to be hyper-aware that the deal will be a crowning achievement in Obama’s legacy.

“Over the coming weeks, Congress will have the responsibility of thoroughly reviewing all of the details in this deal that have so far been hidden,” Sen. John Barasso, R-Wyo., said in a statement. “We’ll hold a robust debate to make sure this deal is centered on protecting Americans -- not the president’s legacy.”

And that potential for permitting Obama to cement a legacy on foreign policy could draw more opposition for the deal than had it been just another routine agenda item.

“I would remind colleagues of the deadly seriousness of the issue at hand,” Senate Majority Leader Mitch McConnell said Tuesday morning on the Senate floor. “This should not be about some political legacy project. This is not some game, either. It’s certainly not the time for more tired, obviously untrue talking points about the choice here between a bad deal and war.”