His own pragmatic flexibility in the face of ideology was on display in 2003, when Mr. Rowhani visited the earthquake struck-region of Bam while serving as secretary of the Supreme National Security Council. Despite the tensions with the United States, Iran had allowed Americans to set up an emergency hospital, and Mr. Rowhani made it a point to visit it and take photographs with American doctors.

His memoirs and several other books describe a life as an integral part of the fabric of Iran’s political establishment, forming friendships at an early age with other clerics bound for positions of power and influence within the Islamic republic.

Mr. Rowhani has described a train journey in 1967 that only in hindsight would seem momentous. Along that trip, he befriended a fellow Shiite cleric who is now the influential head of the office of the supreme leader, Ayatollah Ali Khamenei. Also on that train was a cleric who would turn out to become the national prosecutor. Another influential friend from the pre-revolution years was Ali Akbar Hashemi Rafsanjani, a former president whose endorsement helped ease Mr. Rowhani’s road to the presidency.

It is a snapshot in the life of a man set to become an insider in Iran’s small circle of power.

Because of his dedication to political Islam and influential connections, Mr. Rowhani’s star rose quickly. He was the deputy leader of the Iran-Iraq war effort in the 1980s, served in Iran’s Parliament for 20 years, and for 16 years was in charge of the daily management of the security council, one of the country’s most influential agencies. He is currently the head of the Center for Strategic Research in Tehran, which advises both Mr. Rafsanjani and Ayatollah Khamenei.

“His lifelong career shows he has been at the heart of Iranian politics and his goal is to serve the Islamic republic of Iran,” said Ali Shakouri-Rad, a reformist politician. “The very fact he is elected shows that he is very much accepted by our establishment.”

On Sunday, in Mr. Rowhani’s first major speech since becoming president-elect, that focus was already on display. He warned that the country’s many problems would not be solved overnight, and said he would enter talks with the governing establishment of clerics and commanders for advice.