"It seems in some ways that Iran is inching toward that place where we could have talks and hopefully it'll play out that way," Esper said at the Royal United Services Institute think-tank in London.
Friction between the two countries has grown since Trump last year withdrew from a 2015 international accord under which Iran had agreed to rein in its atomic program in exchange for relief from economic sanctions.
Washington has since renewed and intensified its sanctions, slashing Iran's crude oil sales by more than 80%
At the same time the United States has rebuffed, but not ruled out, a French plan to give Tehran a $15 billion credit line. Rouhani, for his part, on Wednesday gave European powers two more months to try to save the multilateral pact.
The moves suggested Iran, the United States and European powers may be leaving the door open for diplomacy to resolve a dispute over Iran's nuclear work, which the West has suspected was aimed at developing a nuclear weapon, even as they largely stuck to entrenched positions.
Iran denies ever having sought a nuclear bomb.
Trump on Wednesday left open the possibility of a meeting with Rouhani at the upcoming U.N. General Assembly in New York.
Asked about the prospect, Trump told White House reporters anything was possible. "Sure, anything's possible. They would like to be able to solve their problem," he said, referring to inflation in Iran. "We could solve it in 24 hours."
A senior U.S. defense official said Esper and his French counterpart will discuss on Saturday how France's navy could coordinate with Washington to ensure freedom of navigation in the Strait of Hormuz.
Iran said on Friday it had taken a step to further downgrade its commitments to the 2015 deal with the world's most powerful nations, according to Iranian media, in retaliation for U.S. sanctions reimposed on Tehran.
"We continue to believe that we need to be enforcing our sanctions to the maximum extent possible," the U.S. official said when asked about Iran's decision to start developing centrifuges to speed up its uranium enrichment.
Germany, one of the signatories to the deal, reacted to Iran's decision on the centrifuges by saying it was not too late for Iran to change course."We urge Iran not to aggravate the situation further," a German Foreign Ministry spokesman said. "It is not too late for Iran to leave the wrong path it has gone down."