Pragmatic president opened way for serious talks
Iran had denied any work or interest in nuclear arms even after the International Atomic Energy Agency established that Tehran had an organised research and development programme up to 2003 and more scattered activities up to 2009.
But the Islamic republic had little choice but to negotiate an end to the conflict after years of seeing as its revenues from oil sales - its chief income - dry up due to increasing pressure from the US and European Union and other sanctions.
But the talks turned serious only after the pragmatic Hassan Rouhani took office as president in 2013.
For years, Washington had refused to even sit at the same table with Iran, joining the nuclear talks only in 2008, five years after the first international attempts to negotiate a deal.
By the autumn of 2013, however, secretary of state John Kerry had met his Iranian counterpart and Barack Obama had called Mr Rouhani in what was the first direct communication between a US and Iranian president since the 1979 Islamic revolution led to the US embassy hostage taking and a diplomatic freeze.
But the public goodwill quickly faded and the realities of negotiating a mutually acceptable deal sank in. Deadlines were repeatedly extended by months.
The bickering went on to the very end, with the July 14 agreement emerging only after a series of white-knuckle late and overnight sessions, punctuated by threats from both sides to walk away from the table.
Both sides took hits amid the diplomatic manoeuvring - Iran from hardliners accusing their foreign minister Mohammad Javad Zarif of selling out his country's interests and the White House from sceptics at home and abroad - particularly in the Middle East - who said the deal would keep Tehran's bomb-making capacities intact.
All-out lobbying by Israeli prime minister Benjamin Netanyahu against the agreement was also unsuccessful. Warning that Iran has not given up its nuclear ambitions, his office urged world powers on Saturday to respond harshly to any violations of the deal by Iran.
Without that, "Iran will think it can continue to develop a nuclear weapon, destabilise the region and spread terror", the statement said.