Japanese Prime Minister Shinzo Abe has embarked on an ambitious endeavor to play the role of international mediator in the hope of charting a course for dialogue between Tehran and Washington.

As the first Japanese prime minister to visit Iran since 1978, Abe received assurances from President Hassan Rouhani that the oil-rich nation does not want war with the United States -- a welcome relief for resource-poor Japan.

Abe stressed that Japan is an old friend of Iran, in an apparent effort to convince Iran that it is not a mere messenger for U.S. President Donald Trump.

"The words I say to the people of Iran right here may not be easy on your ears," Abe said in a joint press appearance with Rouhani after their talks on Wednesday. "But I dare to say them because I want to be of help to you."

Aside from the symbolism of his two-day visit, Abe faced the risk of Japan being perceived as siding with the United States at the expense of longtime friend Iran, given that tensions in recent months partly stem from Washington's withdrawal from a landmark nuclear deal last year.

It is too early to judge the success or otherwise of Abe's trip, but at least he has been seen to have made efforts to persuade Tehran to take the first yet critical step in a desired change of mode from "confrontation" to "dialogue," according to one foreign policy expert.

"Iran has high expectations of Japan despite some lingering doubts that Japan may only be a U.S. messenger," said Momoyo Kondo, a research fellow at the Middle East Institute of Japan in Tokyo.

"Iran wants Japan to ask the United States to ease its sanctions, return to the nuclear agreement and set the stage for dialogue," Kondo added.

Abe's meetings with Rouhani and Iran's Supreme Leader Ayatollah Ali Khamenei on Thursday gave him a rare chance to exhibit the kind of active diplomacy that some European nations, for example, such as Germany and France, cannot engage in due to the standoff over the 2015 deal that curtailed Iran's nuclear program in return for the lifting of international sanctions.

The timing of his visit was also seen as right, as Abe will host a Group of 20 summit in Osaka in late June where its members are expected to discuss global issues and as he prepares for an upper house election this summer.

Abe has so far failed to put his mark on major foreign policy issues, such as resolving the abductions of Japanese citizens by North Korea in the 1970s and 1980s, or advancing peace treaty talks with Russia by settling a territorial dispute.

A year after Trump withdrew from the nuclear deal and later reinstated crippling economic sanctions, Iran said in May it would suspend some of its commitments and set a deadline of early July to negotiate new terms with other members.

Further ratcheting up tensions in the Middle East, the United States has increased its military presence there.

Trump has thrown his support behind Abe in an effort to reach out to Iran, having previously delivered on his own promise to raise the abduction issue in meetings with North Korean leader Kim Jong Un.

Japanese government officials have stressed the purpose of Abe's trip was not to serve as Trump's messenger but to show Japan's willingness to help curb tensions in the Middle East.

Still, Kazuto Suzuki, a professor at Hokkaido University, said Abe's goal was to win approval from Khamenei, the supreme leader who is more of a hardliner than Rouhani, in his desired role of mediator.

"Mr. Abe has to get a yes to his wish to mediate between Iran and the United States," said Suzuki.

But this did not seem to go well, at least on the surface. After Abe's meeting, Khamenei released a statement saying, "I do not consider Trump as a person worth exchanging any message with and I have no answer for him, nor will I respond to him in the future."

The more ambitious goal of defusing tensions in the region faces numerous hurdles. Depending on how Abe positions himself, Japan's close ties with both Tehran and Washington could have both favorable and unfavorable effects.

"If Japan wants to seriously mediate between Iran and the United States, it will have to shoulder an excessively heavy responsibility," Kondo said, noting that Tokyo also needs to work with countries that see an urgent need for improving the Tehran-Washington relationship, such as Turkey and India.

After talks with Abe on Wednesday, Rouhani said Japan is willing to continue buying crude oil from Iran. Iranian oil accounted for about 5 percent of Japan's total imports before the United States ended its sanctions waivers that had been given to Japan and other buyers.

Abe told Rouhani that Japan would seek to deepen economic ties, including through oil trade, when "the international environment surrounding Iran is right," according to a senior Japanese government official.

The re-introduction of the sanctions waivers is seen as a viable option for the United States if Iran changes its behavior. Abe could be a mediator to negotiate something that would satisfy both sides, said Suzuki.

"Notice the difference with the North Korean case in which the Trump-Kim summits have yet to lead to the lifting of sanctions. That is because the sanctions are by the U.N. Security Council," Suzuki said. "But with Iran, the United States can decide what to do by itself because the sanctions are its own."

In Tehran, Abe recalled his previous visit in 1983 accompanying his late father and then Foreign Minister Shintaro Abe. Over the years, the peoples of both nations, harboring sometimes "complicated" feelings, have continued their exchanges to maintain bilateral ties, Abe said.

"Mr. Abe knows from his previous visit how difficult the situation surrounding Iran is," a Japanese government source said before the prime minister's visit. "Iran also knows he cannot go home empty-handed."