Reached on day 18 of marathon talks in Vienna, the accord is aimed at resolving 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 which formally approved the accord.
Iranian Foreign Minister Mohammad Javad Zarif said the accord with the United States, Russia, China, Britain, France and Germany -- which will provide sanctions relief for Tehran's crippled economy -- was a "historic moment".
More From This Section
"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."
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.
Tehran has accepted allowing the UN atomic watchdog tightly controlled "managed access" to military bases, an Iranian official said.
Allowing visits to military bases to probe any suspicious nuclear activity was a key demand for major powers, but Tehran was deeply uneasy because of fears the inspections were a front for spying on military secrets.
Tehran will slash by around two-thirds the number of centrifuges from around 19,000 to 6,104, an Iranian "fact sheet" confirmed.
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.