JERUSALEM — They were an international odd couple with seemingly little in common, a 40-something African-American born in Hawaii and an octogenarian Zionist born in a shtetl in Poland. But somehow Barack Obama and Shimon Peres hit it off.

When they met, Mr. Obama was still a junior senator on the rise, and Mr. Peres was in the twilight years of a storied career that spanned the lifetime of his nation. Mr. Obama asked for advice. Mr. Peres urged him to disregard the notion that the future was for the young. “Leave the future to me,” Mr. Peres said. “I have time.”

Mr. Peres’s time ran out on Wednesday as he died at 93, two weeks after a stroke. Mr. Obama finds his own time running short, at least his time in the world’s most powerful office, and he is contemplating a second act, always a specialty of Mr. Peres’s. In the end, they had more in common than might have been imagined, two Nobel Peace laureates who found peace maddeningly out of reach.

Mr. Obama’s response to Mr. Peres’s death on Wednesday was striking. He issued a statement that was unusually long and personal, and he called Mr. Peres’s children with condolences even before they had announced their father’s death to the world. Mr. Obama made plans to attend the funeral on Friday, only the second time in nearly eight years in office he has traveled overseas to say farewell to a foreign leader. (The other was Nelson Mandela.)