WASHINGTON (AP) -- The nuclear accord with Iran required a difficult series of compromises for world powers and Tehran.
For President Barack Obama, it meant climbing down from demands that Tehran halt almost all of its enrichment of potential bomb-making material and shutter an underground facility possibly impervious to an air attack. It also meant dropping pledges to secure "anytime, anywhere" inspections and Iran's complete answering of questions related to past weapons work.
But Iran's supreme leader was forced to retreat on some key issues, too. Relief from crippling economic sanctions won't come on Day 1, as he long clamored for, and his country will have to open up military sites to international inspectors at some point if the Islamic Republic is going to fulfill its commitments. Iran also will have to adhere to multiyear restrictions on enrichment and nuclear research and development that Ayatollah Khamenei and other leaders once opposed.
A look at how Iran and world powers found middle ground on some of the agreement's most contentious elements:
Early in Obama's presidency, U.S. officials began backtracking from the long-standing U.S. position that Iran must cease all enrichment of uranium, which can be used for peaceful purposes or transformed into the stuff of nuclear warheads. But Washington wasn't ready to accept more than several hundred centrifuges spinning under tight controls.
The idea went nowhere with Khamenei or Mahmoud Ahmadinejad, Iran's hardline president at the time. Even after the relative moderate Hassan Rouhani became president, Iranian officials still spoke about ramping up from some 20,000 centrifuges to some 190,000 of the machines.
Both sides compromised with a decade-long cap of 6,104 centrifuges, and a little more than 5,000 that can enrich uranium. The Americans said that level would leave Iran far enough away from bomb-making capacity; the Iranians emphasized that their infrastructure remained in place.
When Iran's secret nuclear installation at Fordo came to light in 2009, the U.S. and its European allies demanded its closure. Not only was it hidden from the world community, the site was so deep underground it was potentially bombproof. Iran said it would never scale back efforts there.
The two sides found a solution earlier this year, making it a research institute while allowing the Iranians to continue developing their technological expertise. While Iran can continue running centrifuges at the facility, they have to use gases other than uranium for 15 years.
In a dispute that continued right up to the day of the deal, both Tehran and the West made inspections promises that proved tough to keep. Obama and his aides issued several pledges in recent months about securing the most stringent inspections regime in history, including the ability of U.N. nuclear agency monitors to visit sites wherever and whenever they choose.
Khamenei's response was one of defiance. In fiery speeches to his nation, he insisted he would never open up Iranian military sites to inspectors or allow Iranian nuclear scientists to be interviewed.
The final deal falls in between. International Atomic Energy Agency experts can ask to see military installations of interest and Iran can make counterproposals. But if the experts accept no alternatives, an arbitration panel would decide what access is appropriate. And the U.S. and its European partners can get what they want as the majority of that panel's membership.
PAST WEAPONS WORK
When world powers and Iran reached an interim nuclear pact in November 2013, the United States laid out its position concerning the IAEA's long-stymied investigation of past Iranian atomic weapons work. The final agreement, it said in a statement, "would include resolution of questions concerning the possible military dimension of Iran's nuclear program."
But instead of resolving the matter over the next 20 months, the nuclear agency struggled to get any answers from Tehran. The Iranians insisted that any evidence of wrongdoing was the fraudulent work of U.S. and Israeli intelligence agencies.
Tuesday's accord doesn't solve the matter. It does create a process to do that, and IAEA chief Yukiya Amano said he has a "roadmap" to wrap up his probe by mid-December. The country has failed to meet previous demands for it to come clean, but the West hopes the promise of added sanctions relief will be the difference this time.
While the U.S. agreed to ease sanctions on Iran, it insisted that non-nuclear penalties would remain. Washington had a fight on its hands in the final days of the talks to maintain U.N. bans on Iran importing or exporting conventional weapons, and on Tehran's purchases of ballistic missile technology.
The American fear: Shiite Iran, flush with cash from the nuclear deal, ramping up weapons programs to the great chagrin of Israel and Sunni Arab states, and expanding its military assistance to forces in Syria, Yemen, Lebanon and elsewhere that oppose the U.S. and its allies.
Iran pressed hard for the sanctions to be removed. And it divided the U.S. from some of its partners because Russia and China might benefit from increased arms sales to Tehran.
In the end, Iran accepted the arms embargo for five more years, or shorter if the IAEA certifies it is undertaking no illicit activity. For ballistic missile technology, the ban expires after no more than eight years.
Iran long sought the end of U.S. and international sanctions as soon as the deal came into force. But the United States wanted to postpone lifting the most significant restrictions until the later years of the deal.
The compromise: a phased approach that will allow Iran to collect more than $100 billion in assets frozen overseas early on, while allowing the U.S. to maintain the ability to reimpose sanctions years into the agreement.