In a wide-ranging press conference on Tuesday, the Iranian leader said his government believes "a military foreign intervention should be based on the authorisation of the host country and its people".
"We wish that Turkey's operation in Syria will end at the earliest time," he told reporters in the capital Tehran.
Rouhani's stand on Afrin puts Iran in an awkward position with the United States, which also opposes the military operation and supports the Syrian Kurdish armed group YPG.
The armed group and its other Syrian Kurdish affiliates control a swathe of land in northern Syria, and were credited with defending the Kurds from the Islamic State of Iraq and the Levant (ISIL) and al-Qaeda.
The YPG was also instrumental in retaking ISIL's stronghold of Raqqa last year.
Turkey's President Recep Tayyip Erdogan reiterated his call for the US to withdraw about 1,000 American troops stationed in Manbij, about 60km east of Afrin. He also suggested on Tuesday, he did not trust US statements that it had stopped arming the YPG.
"If the United States says they are sending 5,000 trucks and 2,000 cargo planes of weapons for the fight against Daesh (ISIL), we don't believe this," Erdogan told members of his ruling AK Party in parliament.
"It means you have calculations against Turkey and Iran - and maybe Russia."
On January 20, Turkey and allied armed groups launched the operation against the YPG inside northwestern Syria. At least 14 Turkish troops were killed in fighting as of Sunday.
Ankara said as many as 1,000 YPG fighters have died, while Syria claimed more than a hundred Kurdish civilians have been killed.
|Neighbouring Iran and Turkey are on the opposing sides of the seven-year civil war in Syria [File: AFP]|