Reached on day 18 of marathon talks in the Austrian capital, the accord is aimed at ending a 13-year standoff over Iran's nuclear ambitions after repeated diplomatic failures and threats of military action.
It was hailed by Iran and the European Union as a new chapter of hope for the world but branded a "historic mistake" by the Islamic republic's arch foe Israel.
"I think this is a sign of hope for the entire world and we all know this is very much needed in this time," EU foreign policy chief Federica Mogherini said at the start of a final meeting to formally sign off on the accord.
"It is a decision that can open the way to a new chapter in international relations and show that diplomacy, coordination, cooperation can overcome decades of tensions and confrontation."
Iranian Foreign Minister Mohammad Javad Zarif said the agreement, which will provide sanctions relief for Tehran's crippled economy, was a "historic moment".
"We are reaching an agreement that is not perfect for anybody but it is what we could accomplish and it is an important achievement for all of us," he said. "We are starting a new chapter of hope."
Stringent UN oversight
The deal puts strict limits on Iran's nuclear activities for at least a decade and calls for stringent UN oversight, with world powers hoping that this will make any dash to make an atomic bomb virtually impossible.
In return, painful international sanctions that have slashed the oil exports of OPEC's fifth-largest producer by a quarter and choked its economy will be lifted and billions of dollars in frozen assets unblocked.
The deal -- which was built on a framework first hammered out in April -- is US President Barack Obama's crowning foreign policy achievement six years after he told Iran's leaders that if they "unclench their fist, they will find an extended hand from us".
It also the fruit of his Iranian counterpart Hassan Rouhani's attempts since his election in 2013 to end Iran's isolation 35 years after the Islamic revolution.
The agreement may lead to more cooperation between Tehran and Washington at a particularly explosive time in the Middle East with the emergence last year of the Islamic State group, a common enemy, which controls swathes of Syria and Iraq.
Decades of enmity
Erasing decades of enmity will be tough, however, as seen in supreme leader Ayatollah Ali Khamenei's July 11 comments about US "arrogance" and the burning of US and Israeli flags last week.
"US is perfect instance of Arrogance. Prepare yourselves for more fight against Arrogance," Khamenei was quoted as saying on his English-language Twitter account -- which is off-limits for Iranians.
The prospect of better US-Iran relations alarms Saudi Arabia and other Sunni-ruled Gulf Arab states, which are deeply suspicious of Shiite Iran and accused it of stoking unrest in Syria, Yemen and elsewhere.
Israel, widely assumed to be the region's only nuclear-armed state and which has never ruled out bombing Iran, is also unsettled, seeing the deal as too weak to stop its arch foe getting the bomb.
Israeli Prime Minister Benjamin Netanyahu on Tuesday called the deal "a historic mistake for the world."
Many in the United States agree, not least Obama's Republican opponents who control Congress, which will have 60 days to review the agreement.
During this time Obama cannot waive Congressional sanctions, which for Iran are the most painful.
The deal will prove a "hard sell" in the US Congress, top Republican and Senate Majority Leader Mitch McConnell said in an interview broadcast Sunday.
"It appears as if the administration's approach to this was to reach whatever agreement the Iranians are willing to enter into," McConnell told Fox News on Sunday.
These opponents, backed by legions of lobbyists, are set to launch an intense campaign to try and secure a two-thirds majority to override a presidential veto and scupper the deal.
"Selling the deal back home is likely going to be as much of an uphill battle for the parties as its sealing was," International Crisis Group analyst Ali Vaez told AFP.
And even if the agreement gets past Congress -- the Iranian parliament and the UN Security Council also have to approve it -- implementing the accord could be a rough ride.
The UN nuclear watchdog will have to verify that Iran does indeed scale down its facilities, clearing the way for the complex choreography of untangling the web of UN, US and EU sanctions.
"I think there is a real risk that during the early phase of putting everything in place, that we'll see actions on both sides.. that will undermine the durability of an agreement," said Suzanne Maloney at the Brookings Institution.