In a potentially history-shaping choice of diplomacy over confrontation, the U.S. and other world powers agreed Sunday to give Iran six months to open its nuclear sites to possible daily inspections in exchange for allowing Tehran to maintain the central elements of its uranium program, in a multilayered deal to test Iran’s claim that it does not seek atomic weapons.

The deal is a tentative first step easily presented as a win-win: Iran gives a little on nuclear enrichment and gets some economic sanctions relief in return, as its amiable president waxes diplomatically about continued trust-building with Washington. But America’s closest Mideast ally, Israel, called it a “historic” mistake, fearing that by not insisting on an actual rollback, the world has effectively accepted Iran as a threshold nuclear weapons state. Saudi Arabia and several other Gulf Arab states close to the U.S. hold similar views and many in Congress are dead set against a deal that allows Iran to continue to enrich uranium.

The marathon talks in Geneva appeared at times to be a study in Internet-age brinksmanship and public diplomacy — with all sides sending out signals and statements by Twitter and Facebook — but they also were the culmination of a painstaking process of old-school contacts and secret sessions between Iranian and American envoys that began even before the surprise election of Iran’s moderate-leaning President Hassan Rouhani last June.

The shadow dialogue, mediated by mutual ally Oman, was so sensitive that it was kept from even close allies, such as negotiating partners at the nuclear talks, until two months ago. The pace of the back-channel contacts picked up after Rouhani officially took office in August, promising a “new era” in relations with the West.

“Today, that diplomacy opened up a new path toward a world that is more secure — a future in which we can verify that Iran’s nuclear program is peaceful and that it cannot build a nuclear weapon,” President Barack Obama said in a weekend White House address. Obama referred to publicly known contacts between his administration and Iran and did not specifically confirm the clandestine talks. Senior administration officials, though, said that at least five such meetings were held with Iran since March. Four of those took place after Rouhani’s inauguration and produced significant chunks of the eventual agreement.

But even the extensive groundwork couldn’t clear away all the obstacles to a deal during make-or-break moments in Geneva. The snags were the same that have been at the heart of the impasse since public negotiations resumed 18 months ago: Whether to permit Iran to keep its ability to enrich uranium, the central process in making nuclear fuel for energy-producing reactors and, at higher levels, weapons-grade material.

Iran insisted that trying to block its enrichment was a dead end. For Iran’s leaders, self-sufficiency over the full scope of its nuclear efforts — from uranium mines to the centrifuges used in enrichment — is a source of national pride and a pillar of its self-proclaimed status as a technological beacon for the Islamic world.

In the end, Iran agreed to cap its enrichment level to a maximum of 5 percent, which is well below the 90 percent threshold needed for a warhead.

“For the first time in nearly a decade, we have halted the progress of the Iranian nuclear program, and key parts of the program will be rolled back,” Obama said, stressing that any sanctions relief is reversible should Iran fail to comply with the deal.

What Iran received in return was a rollback in some sanctions — a total package estimated by the White House at $7 billion back into the Iranian economy.

Rouhani portrayed the accord as a victory for Iran’s “right” to enrichment under the Nuclear Non-Proliferation Treaty — even though the West sidestepped using that language in the documents and foreign ministers, including Secretary of State John Kerry, flatly denied such a right had been recognized.

“No matter what interpretive comments are made, it is not in this document,” Kerry told reporters in Geneva. “There is no right to enrich within the four corners of the NPT. And this document does not do that.”

Rouhani, however, using similar phrasing, said the exact opposite.

“No matter what interpretations are given, Iran’s right to enrichment has been recognized,” he said in a nationally televised speech from Tehran just hours after the deal was signed.

Securing a deal that keeps enrichment in place also gives Rouhani’s government some breathing room from Iranian hardliners, such as the powerful Revolutionary Guard, who were so dismayed by the talks and the overtures to Washington that they erected giant banners in Tehran earlier this month depicting U.S. envoys as holding position papers in one hand and attack dogs in the other.

Obama’s critics immediately piled on, led by Israeli Prime Minister Benjamin Netanyahu.

In Jerusalem, Netanyhu called the agreement a blunder of “historic” proportions that leaves Iran as a perpetual nuclear threat.

“Today the world became a much more dangerous place,” Netanyahu said, reiterating a long-standing threat to use military action against Iran if needed, declaring that Israel “has the right and the duty to defend itself by itself.”

The White House said Obama called Netanyahu on Sunday and emphasized “the United States will remain firm in our commitment to Israel, which has good reason to be skeptical about Iran’s intentions.”