U.S. President Donald Trump speaks with Shinzo Abe, Japan's prime minister, during a dinner on May 26, 2019 in Tokyo, Japan.

Japanese Prime Minister Shinzo Abe finds himself in a tough spot as he readies for a visit to Iran.

Abe, who has sought to deflect U.S. President Donald Trump's protectionist and isolationist instincts, is expected to make a rare trip to the Middle Eastern country this month. That comes just as Trump has increased pressure on Tehran and those who deal with it.

Japan has long maintained cordial relations with Iran in part because of its status as a major power and crude supplier in the Persian Gulf, which is the major source of oil for the world's third-largest economy.

But Tokyo depends on the United States for security, so it has tread carefully in the wake of Iran's 1979 Islamic Revolution that turned the country from U.S. ally under the shah to adversary under the ayatollahs.

"Japan's energy policy towards Iran has been an area of struggle for independence from the United States for four decades," Sachi Sakanashi, senior research fellow at the Institute of Energy Economics, Japan, wrote in January on the Atlantic Council's IranSource blog.

"Even when Japan tried to pursue its own energy policy towards Iran, the U.S. has generally had the final say," Sakanashi wrote.

Despite cordial relations, Japan-Iran summits are rare. The last Japanese prime minister to visit Iran was Takeo Fukuda in 1978. Former Iranian President Mohammad Khatami visited Japan in 2000, the first journey by an Iranian head of government in 42 years, according to the Japanese foreign ministry website.

Contacted by CNBC on Tuesday, Sakanashi said that Japan gets 85% of its oil and 28% of its natural gas from the Persian Gulf.

"So the stability of the Persian Gulf region is really important for Japan," she said, adding that Abe likely wants "to do something utilizing Japan's traditionally good relations with Iran."