On a warm day in Washington this fall, President Barack Obama and Israeli Prime Minister Benjamin Netanyahu huddled in the White House, each flanked by a handful of top advisers, including Vice President Joe Biden. Just three days earlier, Obama had held an historic phone call with Iran’s new President Hassan Rouhani, the leader of a country Israel sees as a threat to its very existence.

In the confines of 1600 Pennsylvania Avenue on Sept. 30, just after the high Jewish holidays, Obama revealed to Netanyahu that his administration had been engaged in secret, high-level diplomatic talks with the mortal enemy of the Jewish state. Netanyahu’s immediate public reaction betrayed no surprise, but a day later he launched a full-frontal attack on Iran, delivering a blistering speech at the U.N. General Assembly in which he said the Islamic republic was bent on Israel’s destruction and accused Rouhani of being a “wolf in sheep’s clothing.”

The White House meeting had been scheduled for about an hour, but continued on for 30 more minutes, leaving American and Israeli journalists crowded onto the portico outside the Oval Office to speculate about the discussions underway inside. The two men had and still have an uneasy relationship, and each blames the other for inconclusive results in the Israeli-Palestinian peace process. Yet In statements after the meeting, both leaders tried to display unity rather than airing their differences on Iran in public.

Neither mentioned Rouhani by name. Obama vowed to keep all options, including military action, on the table in order to prevent Iran from obtaining a nuclear weapon. And Netanyahu said he welcomed Obama’s assurances that Iran’s “conciliatory words” must be matched by its actions. At they finished speaking, Obama turned to Netanyahu and said: “Are you hungry? I am. Let’s go eat.” The two leaders, along with Biden, then retreated to Obama’s private dining room for a working lunch.

Israeli media reports now suggest that Israel’s intelligence services were already aware of Obama’s clandestine outreach to Iran, which had begun some seven months earlier, but senior U.S. officials have told The Associated Press that this was the first time America’s closest Mideast ally had been formally notified that it was underway. In fact, at that point, and at Obama’s personal direction, senior U.S. officials had met three times with Iranian officials in a high-stakes bid to address concerns about the country’s nuclear program and explore possibilities for improved ties. Israel, Netanyahu has said, fundamentally disagrees with the administration’s tactics.

On Sunday, just hours after Netanyahu denounced as a “historic mistake” an agreement forged between world powers and Iran to come clean about its nuclear program, Obama called the Israeli leader to reassure him of his vow not to allow Iran to develop a nuclear weapon. Netanyahu again expressed his unease and was unconvinced. He urged the West to reconsider.

The two sides agreed to stay in close touch about their ultimate goal: to rid Iran of the threat of nuclear weapons.

And Obama is not apologizing.

Before Rouhani’s election, while former Iranian President Mahmoud Ahmadinejad was in power, a tense U.S.-Iran relationship seemed unavoidable.

But Obama was determined to test that. In March, a small hand-picked group of officials led by Deputy Secretary of State William Burns and Jake Sullivan, Biden’s top foreign policy adviser, boarded a military plane for Oman to meet Iranian counterparts.

Their travel plans were not on any public itineraries. No reception greeted them as they landed.

It was at this first high-level gathering at a secure location in the Omani capital of Muscat, famous for its souk filled with frankincense and myrrh, that the Obama administration began laying the groundwork for this weekend’s historic nuclear pact between world powers and Iran, The Associated Press has learned.

The AP has learned that at least five secret meetings have occurred between top Obama administration and Iranian officials since March.

Burns and Sullivan led each U.S. delegation. At the most recent face-to-face talks, they were joined by chief U.S. nuclear negotiator Wendy Sherman.

It was at the final get-together that the two sides ultimately agreed on the contours of the pact signed before dawn Sunday by the so-called P5+1 group of nations and Iran, three senior administration officials told the AP. All officials spoke on condition of anonymity because they weren’t authorized to be quoted by name talking about the sensitive diplomacy.

The AP was tipped to the first U.S.-Iranian meeting in March shortly after it occurred, but the White House and State Department disputed elements of the account and the AP could not confirm the meeting. The AP learned of further indications of secret diplomacy in the fall and pressed the White House and other officials further. As the Geneva talks between the P5+1 and Iran appeared to be reaching their conclusion, senior administration officials confirmed to the AP the details of the extensive outreach. They spoke only on condition of anonymity because they were not authorized to discuss by name the secret talks.

The Geneva deal provides Iran with about $7 billion in relief from international sanctions in exchange for Iranian curbs on uranium enrichment and other nuclear activity. All parties pledged to work toward a final accord next year that would remove remaining suspicions in the West that Tehran is trying to assemble an atomic weapons arsenal.

Iran insists its nuclear interest is only in peaceful energy production and medical research. The U.S. and Israel have regularly threatened military action if they believe Iran is about to develop a nuclear weapon.

While the agreement early Sunday — late Saturday in Washington — was concluded to great fanfare and global attention, with Secretary of State John Kerry joining fellow foreign ministers in signing the deal and Obama then presenting it to the nation in a televised White House address, the path there couldn’t have been more secret.

With low expectations, mid-level American officials began in 2011 meeting their Iranian counterparts in Muscat, one of the Arab world’s most tranquil if overlooked metropolises. The process was guided by Sultan Qaboos, Oman’s diminutive but wily monarch, who has cultivated decades of good relations with the United States and his region’s two rivals: Sunni-controlled Saudi Arabia and Shia-dominated Iran.

Qaboos had endeared himself to the Obama administration after three American hikers were arrested in 2009 for straying across Iraq’s border into Iran. As a mediator he was able to secure their freedom over the next two years, prompting U.S. officials to wonder whether the diplomatic opportunity was worth further exploring.

Expectations were kept low for the initial U.S.-Iranian discussions. The officials skirted the big issues and focused primarily on the logistics for setting up higher-level talks. For the U.S., the big question was whether Iran’s leaders would be willing to secretly negotiate matters of substance with a country they call the “Great Satan.”

The private talks were also a gamble for the United States, which cut off diplomatic ties with Iran in 1979 after the Islamic Revolution and the taking of 52 American hostages held for 444 days after rebels stormed the U.S. Embassy in Tehran. To this day the State Department considers Iran the biggest state supporter of terrorism in the world.

When Obama decided to send Burns and Sullivan to Oman, Iran was still being governed by Ahmadinejad, whose inflammatory rhetoric severely worsened the Islamic republic’s relations with the West.

Ahmadinejad’s contested re-election early in Obama’s presidency, followed by the violent Iranian crackdown on pro-reform protesters, had already severely tested the American leader’s inauguration pledge to reach out to America’s enemies.

The goal on the American side, the U.S. officials said, was simply to see if the U.S. and Iran could successfully arrange a process for continued bilateral talks — a low bar that underscored the sour state of relations between the two nations.

Burns and Sullivan were accompanied in Muscat by National Security Council aide Puneet Talwar and four other officials. The senior administration officials who spoke to the AP would not identify whom the delegation met with, but characterized the Iranian attendees as career diplomats, national security aides and experts on the nuclear issue who were likely to remain key players after the country’s summer elections.

Occurring just days after the U.S. and the other powers opened up a new round of nuclear talks with Iran in Almaty, Kazakhstan, the U.S. officials achieved some modest progress. They understood that the Iranians in Muscat at least had some authority to negotiate from Ayatollah Ali Khamenei, who has final say on the nuclear program and many other big Iranian issues.

Beyond nuclear issues, the officials said the U.S. team at the March meeting also raised concerns about Iranian involvement in Syria, Tehran’s threats to close the strategically important Strait of Hormuz and the status of Robert Levinson, a missing former FBI agent who the U.S. believes was abducted in Iran, as well as two other Americans detained in the country.

Hoping to keep the channel open, Kerry then made an official visit to Oman in May, ostensibly to push a military deal with the sultanate. Officials said the trip actually focused on maintaining Qaboos’ key mediation role, particularly after the Iranian election scheduled for the next month.

Rouhani’s June election to Iran’s presidency, on a platform of easing the sanctions crippling Iran’s economy and stated willingness to engage with the West, gave a new spark to the U.S. effort, the officials said.

Two secret meetings were organized immediately after Rouhani took office in August, with the specific goal of advancing the stalled nuclear talks with world powers. Another pair of meetings took place in October.

The Iranian delegation was a mix of officials the Americans had met in March in Oman and others who were new to the talks, administration officials said. All of the Iranians were fluent English speakers.

The meetings encompassed multiple locations and U.S. officials would not confirm the exact spots, saying they did not want to jeopardize their ability to use the same venues in the future. At least some of the talks continued to take place in Oman.

The private meetings coincided with a public easing of U.S.-Iranian discord. In early August, Obama sent Rouhani a letter congratulating him on his election. The Iranian leader’s response was viewed positively by the White House, which quickly laid the groundwork for the additional secret talks. The U.S. officials said they were convinced the outreach had the blessing of Ayatollah Khamenei, but would not elaborate.

As negotiators worked behind the scenes, speculation swirled over a possible meeting between Obama and Rouhani on the sidelines of the U.N. General Assembly in September, which both attended. Burns and Sullivan sought to arrange face-to-face talks, but the meeting never happened largely due to Iranian concerns, the officials said. Two days later, though, Obama and Rouhani spoke by phone — the first direct contact between a U.S. and Iranian leader in more than 30 years.

It was only after that Obama-Rouhani phone call that the U.S. began informing allies of the secret talks with Iran, the U.S. officials said.

Obama handled the most sensitive conversation himself, briefing Israeli Prime Minister Benjamin Netanyahu during a Sept. 30 meeting at the White House. He informed Netanyahu only about the two summer meetings, not the March talks, in keeping with the White House’s promise only to tell allies about discussions with Iran that were substantive.

The U.S. officials would not describe Netanyahu’s reaction. But the next day, he delivered his General Assembly speech, blasting Rouhani as a “wolf in sheep’s clothing” and warning the U.S. against mistaking a change in Iran’s tone with an actual change in nuclear ambitions. The Israeli leader has subsequently denounced the potential nuclear agreement as the “deal of the century” for Iran.

America’s negotiating partners were then informed, though European officials said they assumed something was cooking between Washington and Tehran based on the surprising progress toward a deal after more than a decade of stalemate.

The secrecy of Obama’s effort may explain some of the tensions between the U.S. and France, which earlier this month balked at the proposed accord, and with Israel, which is furious about the agreement and has angrily denounced the diplomatic outreach to Tehran.

Burns and Sullivan continued their efforts behind the scenes at this month’s larger formal negotiations between world powers and Iran in Geneva, though the State Department went to great lengths to conceal their involvement.

Their names were left off of the official delegation list. They were housed at a different hotel than the rest of the U.S. delegation, used back entrances to come and go from meeting venues and were whisked into negotiating sessions from service elevators or unused corridors only after photographers left.

Congress hasn’t been notified in detail about the secret diplomacy. That could also pose a challenge for Obama, who has been waging a tense battle with Republicans and Democrats alike to prevent them from enacting new sanctions against Iran at the same time he has been offering Tehran some relief.

Several lawmakers from both parties openly scoffed Sunday at the terms of the deal between world powers and Iran. And in a reflection of the primary role played by his administration, some already are referring to the end result as Obama’s agreement. None said they had been briefed on the secret talks.

“I don’t know how to react,” Sen. Bob Corker, the Senate Foreign Relations Committee’s top Republican, said on “Fox News Sunday.” ”The administration has been trying to set the framework for these discussions for some time and I guess I’m not really particularly shocked that this has occurred.”