This is one of the first regional expressions of support for Tehran.
A source in Turkish President Tayyip Erdogan’s office said he discussed the week-long unrest in Iran during a telephone conversation with Rouhani.
“The Iranian president told Erdogan he hoped the protests would be over “in a few days”, the source said.
Erdogan’s sympathetic comments follow an improvement in relations between Ankara and Tehran, which have worked together in recent months to reduce violence in Syria, despite backing opposing sides in the conflict for several years.
Rouhani has said on Sunday that Iranians had the right to protest and criticize the authorities but their actions should not lead to violence or damage public property.
Erdogan told Rouhani “that he found his comments about not violating the law while exercising their right to peaceful protests was appropriate”, the source said.
On Wednesday pro-government rallies in several Iranian cities drew thousands of marchers waving Iranian flags and pictures of Supreme Leader Ayatollah Ali Khamenei.
Turkey’s ties with Iran expanded last year as Ankara’s relations with the United States, Israel and Saudi Arabia – Tehran’s main international opponents – all frayed.
Secular but overwhelming Sunni Muslim Turkey shares a border with mainly Shi‘ite Muslim Iran and they are the two biggest non-Arab powers in the Middle East region.
In August Iran’s military chief of staff visited Turkey, which is a member of the NATO military alliance, for talks on cooperation in the Syrian conflict and counter-terrorism.
“Iran’s stability is important for us. We are against foreign interventions in Iran,” Turkey’s Foreign Minister Mevlut Cavusoglu said, in remarks quoted by television channel NTV.
“If the leadership is to change in Iran, the Iranian people will do this,” he said.
CNN Broadcaster, Turk, said Cavusoglu also echoed Rouhani’s suggestion that the U.S. and Israel had provoked unrest.
“There are two people supporting the demonstrations in Iran: (Israeli Prime Minister Benjamin) Netanyahu and (U.S. President Donald) Trump,” it quoted Cavusoglu as saying.
Netanyahu has praised Iranian anti-government protesters, while describing as “laughable”, accusations that Israel was behind the demonstrations.
Trump has tweeted that Iranians are “finally acting against the brutal and corrupt Iranian regime”.