The North Korean foreign minister said he had briefed Rouhani on the nuclear negotiations between Pyongyang and Washington, according to Iran's Donya-e-Eqtesad newspaper.
Iran and North Korea have maintained relations for decades.
Soo Kim, a former CIA intelligence analyst who specializes in North Korea, said that the Iran visit sent a message to the international community.
The North Koreans were taking a “two-pronged” diplomatic approach by continuing denuclearization negotiations with the U.S. while also pursuing diplomacy and “ally-building” with countries such as Iran.
“It’s a way to keep us on our toes," Soo Kim added. "They’re playing a game with us, they’re giving us hope that things are going to progress but at the same time they’re not really showing us anything concrete.”
Pyongyang has tested a total of 23 missiles since Trump took office, and 15 of those tests involved nuclear-capable ballistic missiles. The November 2017 launch of which appeared to be an intercontinental ballistic missile, or ICBM, flew farther than any of Kim Jong Un's previous tests. The North claimed it could reach anywhere in the mainland U.S.
However, analysts say it's hard to prove or debunk North Korea's claim that it could hit faraway American targets such as New York or Washington.
While Iran has maintained its nuclear program is for peaceful purposes, before the June summit with Trump North Korea had repeatedly threatened to attack the U.S. and South Korea.
Andrei Lankov, a professor of Korean studies at Kookmin University in Seoul, said that there was "active cooperation of nuclear and missile issues" between Iran and North Korea.
He added that Pyongyang and Tehran "do exchange knowledge, they do probably exchange technology," describing it as "an open secret" that's been going on for many years.
Lankov said North Korea has been selling arms to Iran at least since the mid-1980s, including missiles used by Tehran during the Iran-Iraq War.
He described Iran as a "very profitable partner" for North Korea.
Lankov added: "North Koreans tend to make alliances with anti-American radicals of any kind."
Trump has called the Iran nuclear agreement "the worst deal ever" and has demanded Tehran end its military support for the Syrian government and regional militant groups like Lebanon's Hezbollah.
The U.S. is also seeking to get Iran to curb its ballistic missile program, which was not restrained as part of the nuclear deal. Tehran has maintained that its missiles are not designed to carry nuclear weapons.
Critics of Trump's decision say that the Iranians had acceded to international inspections and dramatically reduced their nuclear program as a result of the landmark agreement. So it was working, and by stepping away from a pact that took years to negotiate and imposed important concessions on Iran, the Trump administration was making it less likely that Tehran wouid come to the negotiating table again soon, they say.
Before Trump withdrew from the deal, France's Emmanuel Macron, Germany's Angela Merkel and Britain's Theresa May had pleaded with the president to give them leeway to address his concerns in a "side deal," a new negotiation to limit Iran's missiles, extend the term of the original Iran deal, and confront Iran's support for terrorism.
Despite warming relations with the U.S., North Korea remains subject to U.S. sanctions.
And like Kim Jong Un's government, Iran argues that sanctions are not conducive to negotiations.
"Negotiations and sanctions at the same time is meaningless," Rouhani said in a televised address on Monday. "If someone stands in front of his rival or enemy and pushes a knife against their arm and seeks talks, the response is that he should first put the knife in his pocket and come to the negotiating table and use logic."