Secretary of State John F. Kerry talks with Iranian Foreign Minister Mohammad Javad Zarif in May in Geneva during talks on the future of the Iranian nuclear program. (Susan Walsh/AP)

Secretary of State John F. Kerry and Iranian Foreign Minister Mohammad Javad Zarif are a study in contrasts.

Kerry, tall with a shock of silver hair, is the picture of a patrician U.S. diplomat in his pinstriped suits, brightly colored silk ties and wingtips.

Zarif, short, stout and balding, hews to traditional Iranian collarless shirts, buttoned high at the neck, accompanied by a plain suit and black lace-up shoes.

Their personalities are markedly different, too. Where Kerry usually keeps his emotions in check when in public, Zarif openly exhibits a full gamut of them. He often comes off as affable but is known for flashes of anger in a voice so loud he has said Iran's supreme leader once advised him to smile more and shout less.

Despite their differences in style and world outlook, John and Javad — as they call each other — have managed to form a working relationship based on respect over the course of the Iran nuclear talks — a striking outcome for two men representing countries with decades of deep and sometimes bloody enmity, at odds on almost every world issue.

Diplomats caution that an agreement to curb Iran’s nuclear program and lift sanctions will not result anytime soon in warmer relations between Iran and the United States. Antipathy will linger, probably for years, over Iran’s support for groups such as Hezbollah and Hamas, and its human rights record.

But as the Iran nuclear talks reach a denouement — with a deal expected to be finalized or fall apart in the next few days — the example set by the two diplomats could be a model for future progress in the relationship.

“The reality is, either both win or both lose,” said Trita Parsi, the president of the National Iranian American Council, who is writing a book about the nuclear talks. “Sometimes two people need to build trust . . . before you can build it between two nations.”

Kerry, 71, and Zarif, 55, are those two people, though they are not the only ones who have gotten to that strange in-between place of being friendly but not friends during more than 18 months of intense negotiations that were kick-started after Hassan Rouhani was elected president of Iran in 2013.

Each country has dozens of experts on nuclear technology and sanctions who have spent many months together negotiating in various European capitals.

They have marked anniversaries with each other instead of their spouses, and commiserated when they missed children’s birthdays and family vacations.

But when the going got tough, the negotiators turned to the two principals to hash out the details. According to a State Department official, during his 2½ years as secretary of state, Kerry has logged more time one-on-one with Zarif than with any other foreign minister.

Before the talks, the two men had met, though they can’t remember exactly where, according to the official, who, like others, spoke on the condition of anonymity in order to discuss the talks and the relationship between the principals. But they certainly knew of each other.

As chairman of the Senate Foreign Relations Committee, Kerry was part of the initial overture to Iran when talks over the country’s nuclear program appeared to have foundered. He made a unannounced trip to Oman in 2011 to meet with Sultan Qaboos bin Said and open a secret dialogue with Iran, exploring whether the two countries could find areas of understanding on the nuclear issue. And with an Iranian American son-in-law, Kerry was already familiar with some cultural aspects.

Zarif spent 2000 to 2007 as Iran’s representative at the United Nations, and met many times with American politicians, including Joe Biden and Chuck Hagel when they were still senators. Zarif spent more than half his adult life in the United States, earning degrees from San Francisco State University and the University of Denver. His children were born in the United States.

Their first formal meeting was at the U.N. General Assembly in 2013. What was supposed to be a quick, nice-to-meet-you meeting in a small room off the Security Council’s main chamber turned into a conversation that stretched more than 20 minutes.

Though five other nations — Russia, China, France, Britain and Germany — are involved in the negotiations with Iran, many of the intricate details have been thrashed out between Kerry and Zarif.

“The secretary very much believes in the power of personal diplomacy,” a Kerry aide said. “He believes the way to get things done is to sit in a room, develop a working relationship and work out the tough issues together.”

Both men have an appreciation for the stiff domestic opposition each faces. That has contributed to the sentiment most commonly used by aides to both men to describe their relationship: respect.

At the announcement of a framework agreement in April, Zarif thanked Kerry for investing so much in the negotiations, which he said had been conducted with “mutual respect.”

“They’re not friends, by any stretch,” a second Kerry aide said. “But there’s respect on both sides.”

“They have the same interest,” an Iranian official at the talks said. “It’s not personal.”

Their interactions have sometimes gone beyond the usual diplomatic exchanges. When Kerry broke his leg on May 31 after a meeting with Zarif, one of the first messages he received was an e-mail from Zarif expressing his hope that Kerry would make a speedy recovery. Protocol dictated only a note sent to a U.S. embassy.

The personal diplomacy has brought a measure of suspicion, particularly for Zarif.

At talks in Geneva in January, Kerry impulsively suggested that they go for a stroll along the riverbank. Photographs of the two of them chatting casually earned Zarif grief from hard-liners in Tehran. Some members of parliament summoned him to explain the episode, and one Iranian critic called it simply wrong to show intimacy with the enemy.

That is one reason why Zarif needs Iran’s supreme leader, Ayatollah Ali Khamenei, to repeatedly praise him in speeches.

“He’s looked on with suspicion for having spent too much time with the Americans,” Parsi said. “Some people wonder how they can trust him.”

If a deal is reached, Kerry’s and Zarif’s names will go into the history books, along with the presidents they serve. But once they leave office, they probably will never sit together again.

“It’s a working relationship,” the Kerry aide said. “You don’t have the luxury of developing a friendship. They understand each other, despite differences at the table. Generally, they just want to see if they can get a deal done.”