(Adds quotes and details)
By Matt Spetalnick
WASHINGTON, July 14 (Reuters) - The sealing of a nuclear pact with Iran marks the biggest foreign policy gamble of Barack Obama's presidency - a legacy-defining achievement that could yet backfire if Tehran exploits any loopholes or escalates tensions in the Middle East.
No other foreign policy challenge bears Obama's personal stamp more than the final nuclear accord reached with Iran on Tuesday, and none poses a more critical test of his doctrine of talking to America's enemies to avoid having to confront them.
That policy has already resulted in the restoration of diplomatic ties this month with communist Cuba, ending more than five decades of hostility. But the potential rewards and perils are far greater for the Iran deal, which offers Obama his best hope of salvaging an otherwise shaky record in the Middle East.
Obama's engagement - sometimes at the level of minute technical detail, according to aides - has contrasted with a more aloof approach toward some other geopolitical problems like Syria's civil war and Ukraine's separatist conflict.
Obama, who came into office in 2009 offering to extend a hand to Iran's leaders if they would "unclench their fist," secured a historic opening with a phone call to the Islamic republic's president and then exchanged secret letters with its Supreme Leader Ayatollah Ali Khamenei.
As talks came down to the wire in Vienna, Obama was on the phone to Secretary of State John Kerry regularly from Washington, at least once by secure video link, giving "guidance" to the negotiating team.
When White House aides informed him on Monday night that the deal was complete, he insisted on calling Kerry to get the news first-hand, a senior administration official said.
Speaking at the White House, Obama sought to discredit any efforts to derail the agreement by insisting that no deal would mean "a greater chance of more war in the Middle East."
He said a diplomatic approach was the best way to coax Iran away from "the path of violence and rigid ideology," though he acknowledged it would not be easy.
But if the critics are proven right, Obama could go down in history as the president who only bought time before allowing Tehran to go nuclear. That could spark a regional arms race.
Analysts mostly agree, however, that it could be years before it is known whether or not Obama's gamble paid off.
Obama, who controversially won the Nobel Peace prize barely nine months into his first term, must overcome accusations from hawkish lawmakers that he abandoned many of his original "red lines" and compromised on others.
Despite Obama's hailing of the final deal as defusing Iran's nuclear threat, initial U.S. demands dropped along the way included fuller dismantling of Tehran's nuclear architecture and rollback of its ballistic missile program.
The terms of the final deal cast doubt on whether inspectors will have the full "anytime, anywhere" access once demanded at Iranian military sites, and will also allow Tehran to conduct research and development using its more efficient centrifuges. U.S. officials insist, however, that Iran also gave ground.
Obama "got what he wanted: a smaller, slower, more easily constrained and monitored nuclear program, no pre-emptive Israeli strikes and no need for an American one," said Aaron David Miller, a former Middle East negotiator for Republican and Democratic administrations.
"But Iran got more," he added, citing billions of dollars in sanctions relief "to support bad actors without giving up a large nuclear infrastructure that could allow them to weaponize should they choose to do so."
The deal is the biggest step toward rapprochement between Iran and the West since the 1979 Islamic Revolution and may open new ways to address one of the root causes of tension in the region. Shi'ite Iran has a big hand in sectarian conflicts ranging from Syria to Iraq to Yemen.
Much work remains for Obama to entrench the deal, which lifts sanctions on Iran in exchange for limits on its nuclear work that the West has suspected was aimed at creating a nuclear weapon. Iran denies it has been seeking a bomb.
He must now convince a skeptical Congress not to sabotage the agreement while reassuring allies such as Israel and Saudi Arabia who fear that Iran will be empowered to expand regional influence.
With the possibility of a Republican winning the presidency in 2016, Obama must also try to ensure that his successor is not able to scrap the agreement.
White House aides say critics' demands for a better deal were unrealistic, and Obama declared on Tuesday it would have been "irresponsible" to walk away from it.
The most immediate challenge for Obama will be to clear the obstacles in the Republican-controlled Congress, which will have 60 days to review the Iran agreement.
"The president will have to work harder than ever to explain what the deal actually does, how it blocks the nuclear pathways and what happens if Iran cheats," said Dennis Ross, Obama's former top Middle East adviser.
Many fear that even if Iran does not covertly work toward a bomb it would remain a nuclear-weapons threshold state able to race ahead once restrictions on its uranium enrichment activities begin expiring in a decade.
That could leave a future U.S. administration with the decision whether to go to war to stop it.
Additional reporting by Warren Strobel and Patricia Zengerle in Washington and Arshad Mohammed in Vienna; editing by David Storey, Stuart Grudgings, G Crosse