Rouhani, the first Iranian president to visit Japan in 19 years, told Prime Minister Shinzo Abe that the nuclear agreement with world powers is very important and that Washington's unilateral withdrawal was "unreasonable."
Abe, in his opening remarks, urged Iran to fully comply with the agreement and play a constructive role in achieving peace and stability in the region. Abe expressed concern about rising tensions in the Middle East and pledged to do as much as possible to help restore regional stability.
The Middle East supplies more than 80% of Japan's oil.
Japan, a U.S. ally that has traditionally had friendly relations with Iran, also seeks to serve as a mediator between Tehran and Washington. Abe has said such a role is expected by the international community.
Rouhani, who was in Malaysia to attend an Islamic conference, arrived in Tokyo on Friday afternoon for an overnight visit to meet Abe and have dinner with him, Japanese Foreign Ministry officials said.
Tensions have escalated between Tehran and Washington since President Donald Trump's decision last year to withdraw from Iran's 2015 nuclear deal.
Abe, who has developed friendly ties with Trump, traveled to Iran in June in an unsuccessful effort to encourage Iran and the U.S. to hold talks to reduce tensions. U.S. sanctions on Iran, which block it from selling crude oil abroad, have crippled its economy, and Tehran has gradually reduced its commitment to the nuclear deal.
Abe's government is to announce a contentious plan to send its military to the Middle East to ensure Japanese oil tankers' safety. Japan's troop dispatch won't be part of a U.S.-led coalition protecting Middle East waterways, apparently an attempt to maintain neutrality in a show of consideration to Iran.
Abe plans to thoroughly explain this to Rouhani to gain his understanding, officials said.
Sending warships to areas of military tension is a highly sensitive issue in Japan because its pacifist post-World War II constitution strictly limits the use of force by the military. Abe, however, has gradually expanded Japan's military role in recent years.
In June, a Japanese-operated tanker was attacked in the Gulf of Oman. Washington said Iran was responsible and urged Japan to join the U.S.-led military initiative.
Rouhani may ask Japan to resume purchases of Iranian oil, but that may be difficult because of international sanctions still in place. Japanese companies have stopped importing Iranian oil since May.