Rouhani will pay a working visit to China and attend the summit of the China and Russia-led security bloc the Shanghai Cooperation Organization, the ministry said.
It did not give exact dates for his visit, but the summit is scheduled to be held on the second weekend of June in the northern Chinese city of Qingdao.
“Our hope is that China and Iran will have close consultation on the basis of observing the deal and push forward development of bilateral cooperation,” Chinese deputy foreign minister Zhang Hanhui said at a briefing.
“We should together look into how to avoid major disruption of joint projects between the two sides,” he added.
Russia has previously argued that with Western sanctions against Tehran lifted, it could finally become a member of the bloc which also includes four ex-Soviet Central Asian republics, Pakistan and India.
The 2015 agreement between Iran and world powers lifted international sanctions on Tehran. In return, Iran agreed to restrictions on its nuclear activities, increasing the time it would need to produce an atom bomb if it chose to do so.
Since U.S. President Donald Trump withdrew the United States this month, calling the agreement deeply flawed, European states have been scrambling to ensure Iran gets enough economic benefits to persuade it to stay in the deal.
Russian President Vladimir Putin, as well as the leaders of Kazakhstan and Kyrgyzstan, were also invited to hold official bilateral meetings with Chinese President Xi Jinping during the summit, the foreign ministry said.
The summit, which runs from June 9-10, will attempt to create new agreements on security issues such as counter-terrorism and drug smuggling among the seven member bloc.
Jointly led by Russia and China, the SCO was launched in 2001 to combat radical Islam and other regional security concerns. India and Pakistan became full members last year.
Iran has long eyed an SCO membership and China has said it supports its application.