Hasan Rouhani, a 37-year-old senior foreign affairs advisor in the Iranian government, and his country’s future president, sat with a delegation of White House officials on the top floor of what was once the Hilton hotel in Tehran. It was May 27, 1986, and Rouhani had come to secretly broker a deal with the Americans, at great political and personal risk.

The U.S. team’s ostensible purpose was to persuade Iranian leaders to assist in the release of American hostages held in Lebanon, something Rouhani was willing to do in exchange for the United States selling missiles and weapons systems to Iran. But the group, which consisted of senior National Security Council staffers, including a then little-known Marine lieutenant colonel named Oliver North, had a second and arguably more ambitious goal: to forge a new political alliance with moderate Iranian leaders, such as Rouhani and his bosses, the men who ran the country.

In those meetings, the man to whom U.S. officials are now turning as the best hope for a rapprochement with Iran, after more than three decades of hostilities, showed himself to be a shrewd negotiator, ready to usher in a new era of openness. But he was also willing to subvert that broader goal and string the Americans along to get what he wanted — more weapons. If there is a window into how Rouhani thinks today and how he will approach negotiations over Iran’s nuclear program, it may be those few days in May he spent in high-stakes talks with the Americans over hostages and the countries’ shared futures.

Rouhani knew that helping to free the hostages held by Hezbollah, the terrorist group with which Iran held some influence, was a top priority for President Ronald Reagan. The U.S. president had personally committed to the families that he’d do whatever it took to rescue their loved ones. A televised homecoming would be a political triumph for Reagan.

"By solving this problem we strengthen you in the White House," Rouhani told North and his colleagues. "As we promised, we will make every effort."

But it would not come without cost. Rouhani and his cohort, a group of lower-level functionaries in the regime, kept turning the conversation back to the subject of weapons. The Americans had pledged to have a plane full of missile parts on its way to Tehran within 10 hours of the hostages’ release. The Iranians wanted the missiles first. When it was clear that wouldn’t happen, they offered to help secure the release of two hostages and said that after further negotiations they’d try for two more.

Rouhani did believe in the broader mission. "You did a great job coming here, given the state of relations between us," Rouhani told the Americans. He thought they could start to work together, though it would be slow going. "I would be surprised if little problems did not come up. There is a Persian saying: Patience will bring you victory — they are old friend. Without patience, we won’t reach anything. Politicians must understand this."

But the bartering over missiles frustrated the Americans. North had handled all the logistics for the meeting and was overseeing the arms sales. But the higher strategy was led by Reagan’s former national security advisor, Robert "Bud" McFarlane. Freeing the hostages was a priority, but McFarlane worried that it threatened the chances of what he called the "new political development" with Iran’s moderates.

McFarlane hoped that Rouhani was the key to success. A prior day of negotiations with the lower-level officials had revealed them to be a bunch of amateurs. The Iranians had shown up an hour late at the airport to greet McFarlane and his team, who were traveling under false identities to keep the mission a secret. When they finally started talking at the hotel, the Iranians were by turns hospitable and paranoid. In one minute they were welcoming the Americans with pledges of "goodwill" between their countries. In the next, they were accusing the Americans of reneging on their agreement to send a fresh round of missile parts to Tehran.

"At bottom, they really are rug merchants," McFarlane told National Security Advisor John Poindexter in a cable later that night. The Americans needed to "get beyond their level [of authority] if we are to do any serious business here."

McFarlane’s hopes were answered the next day when Rouhani showed up. "As it turned out this man was a cut above the bush leaguers we had been dealing with," wrote McFarlane, who, when he was still serving in the White House, had helped set up the initial arms-for-hostages exchange.

"We are ready to listen in all areas," Rouhani told his guests. "Though we knew we won’t agree in every area, we will agree on some subjects."

The account of the negotiations is contained in a near-verbatim transcript written by a National Security Council (NSC) staffer who was part of the U.S. delegation. It was published in the Tower Commission report, which later investigated the arms sales.

The transcript shows that Iran’s leaders were afraid they’d be deposed if more hard-line elements in the regime or the public at large discovered they were meeting with the Americans. Howard Teicher, the NSC staffer who wrote the account of the meeting, told Foreign Policy that Rouhani used a pseudonym to protect himself in case the details of the discussion leaked. In the Tower report, Rouhani appears only as "senior foreign affairs adviser."

"Our relations are dark. They are very bad," Rouhani told his guests. "Maybe you don’t like to hear it, but I must be outspoken. The Iranians are bitter." He urged caution. "As a government, we don’t want to be crushed tomorrow. We want to stay in power and solve these problems between us." Rouhani reminded the Americans that many of his countrymen called the United States "the Great Satan."

Many still do. Today, Rouhani finds himself once again extending a hand to American leaders but also keeping them at arm’s length. Reportedly, the Iranians called off a possible encounter between Rouhani and President Barack Obama on the sidelines of the U.N. General Assembly meeting this week for fear of how the photo-op would go over back in Tehran.

"They still cannot overcome their more immediate problem of how to talk with us and stay alive," McFarlane wrote in 1986. "But from the tenor of [Rouhani’s] … statements, conviction, and knowledgeable expression of what is possible in the way of a stable cooperative relationship, I believe we have finally reached a component Iranian official — and that’s good."

The Americans and the Iranians bonded most strongly over their mutual foe, the Soviet Union. Although the USSR had formally recognized Iran’s revolutionary government in 1979, the relationship turned toxic when the Soviets began supplying arms to Iran’s archenemy, Iraq. The Ayatollah Ruhollah Khomeini had also judged the communist regime incompatible with Islam.

Teicher gave Rouhani a summary of the Soviet military threat to Iran — the number of divisions that were able to strike the country, the frequency of cross-border strikes from Afghanistan into Iran. North said the Soviets would try to expose the secret talks between Rouhani and the White House, and he suggested that the two sides install a secure communications line. (Unbeknownst to Iran, the Reagan administration was running its own secret interactions with Iraq. The Americans knew Iraq used chemical weapons against Iranian troops but did nothing to alert Tehran. This subject was apparently never discussed in the meetings.)

Rouhani was glad to have the tactical information about Soviet forces. And he was eager to get more U.S. weapons to counter the military threat to his country. He indicated that "mujahideen" fighters training in Iran were already attacking Soviet forces in Afghanistan.

But even in their shared animosity for the communists, the strains of mistrust were evident. Iran felt existentially threatened, and Rouhani didn’t think the Americans fully appreciated that. They needed to do more to help Iran defend itself, with U.S. weapons.

"I am sorry to be so harsh," Rouhani said. "But I need to be frank and candid to overcome differences.… I am happy to hear you believe in an independent sovereign Iran. We are hopeful that all American moves will be to support this dialogue. But we feel the whole world is trying to weaken us. We feel and see the Russian danger much more than you. You see the threat with high technology [apparently a reference to nuclear missiles]. We feel it, touch it, see it. It is not easy to sleep next to an elephant that you have wounded."

For all the distance between the two sides, though, Rouhani looked for ways to bring them closer together. He pledged that he’d continue pressing for the release of hostages held by terrorists in Lebanon.

This is what the Americans had wanted, but they didn’t want to lose the diplomatic momentum. North wanted McFarlane to talk face to face with Iran’s speaker, prime minister, and president. Rouhani said it was far too soon for that.

"Can a secret meeting be arranged with McFarlane and your leaders?" North asked.

"You can be sure that this will be conveyed," Rouhani said, adding that after the U.S. hostages were free and the military equipment had been delivered, "there will need to be more positive steps." Later, he added, "We have to prepare the people for such a change. Step by step. We need to prepare the nation. Meetings between U.S. and Iranian leaders will take place in this context. If you are serious about solving problems, I am sure official trips and high-level meetings will take place."

Those meetings never came to pass. McFarlane spoke privately with Rouhani the next day. "It was a useful meeting on the whole," he cabled back to Poindexter. "I made it clear that regarding Iran we sought a relationship based upon mutual respect for each other’s sovereignty, territorial integrity and independence."

But it had become clear that both sides were talking past each other over the sequence of events that had to happen before the hostages could be finally released. The Iranians made contact with the hostage-takers, but now they were making extraordinary demands, including the complete withdrawal of Israeli forces from the Golan Heights and southern Lebanon. McFarlane saw immediate release of the hostages as unconditional. Whoever may have told Rouhani otherwise had been mistaken.

"My judgment is that we are in a state of great upset," McFarlane told Poindexter, "schizophrenic over their wish to get more from the deal but sobered to the fact that their interlocutors may have misled them."

Later that night, McFarlane and Rouhani again met privately. The talks fell apart. "McFarlane concludes they’re just stringing us along," Teicher wrote in his notes.

Rouhani left and returned the next morning. "You are not keeping the agreement," McFarlane said. "We are leaving."

The Americans headed for the airport. As they boarded their plane, an Iranian official pleaded with them, "Why are you leaving?"

McFarlane said the Iranians had failed to honor their commitment. "This lack of trust will endure for a long time. An important opportunity was lost here."

The plane left Tehran shortly before 9 a.m.

North could see that McFarlane felt defeated. He wanted to bolster McFarlane’s spirits. So when the plane landed in Tel Aviv to refuel, North told McFarlane a secret: All was not lost. The prior arms sale to Iran had resulted in an unexpected profit. North and his colleagues at the White House had secretly diverted the money to the Contra guerrilla forces in Nicaragua, who were fighting to overthrow the socialist government.

McFarlane would later tell investigators his first reaction upon hearing what North had done: "Oh shit."

Congress had repeatedly tried to block the flow of money to the Contras and had passed a law barring the intelligence community from sending any funds. What North had just described, and what McFarlane was hearing for the first time, was the covert scheme that would become known as the Iran-Contra Affair. It resulted in felony indictments against North, Poindexter, and other administration officials, and it threatened Reagan with impeachment. McFarlane pleaded guilty to misdemeanor charges associated with the scandal.

The affair dashed any hopes for a new dawn with Iran. But even if it had never become public, the gap of trust between the two sides was probably too great to bridge. It can be measured to this day. When Secretary of State John Kerry meets with his Iranian counterpart in New York this week to discuss Iran’s nuclear program, it will be the first face-to-face discussions between senior leaders of both countries since that meeting in Tehran, 27 years ago.