Turkey and Iran have voiced strong opposition to a referendum on Kurdish independence scheduled next month in neighboring Iraq during a rare visit to Ankara by Tehran's army chief of staff on August 16.

Turkish media said it was the first such visit since Iran's 1979 Islamic Revolution.

"There have been no such visits between the two countries for a long time, but considering regional developments and security issues - border security and the fight against terrorism - there was a need for such a visit," Iranian General Mohammad Hossein Baqeri told Iranian state television upon his arrival in Ankara on August 15.

Baqeri said after talks with Turkish President Recep Tayyip Erdogan late on August 16 that they agreed the Kurdish independence referendum in Iraq could stir unrest in the entire region.

Kurds are a sizable minority in Iran, Iraq, Syria, and Turkey, and have factions pushing for autonomy -- sometimes violently -- in each of those adjoining countries.

"Both sides stressed that if the referendum is held, it will be the basis for the start of a series of tensions and conflicts inside Iraq, the consequences of which will affect neighboring countries," Baqeri was quoted as saying by Iran's IRNA news agency.

"Holding the referendum will get Iraq, but also Iran and Turkey involved and that's why the authorities of the two countries emphasize that it is not possible and should not be done."

Erdogan hosted Baqeri at his presidential palace with Turkey's defense minister and top general also in attendance, Erdogan's office said. The talks also touched on efforts to forge peace in Syria, where the two countries back forces on opposing sides.

Turkey, Iran, and the Iraqi government in Baghdad have all expressed opposition to the plan by Iran's autonomous Kurdish region to hold the referendum on independence, but Kurdish leaders have not canceled the September 25 vote.

The 5 million voters in Iraq's Kurdish region are considered likely to approve the referendum, but Kurdish leaders there have said the vote will not be binding and will be only advisory in nature.

Iraq's Kurdish minority, which already has considerable autonomy, has lived relatively peacefully with the central government in Baghdad despite recurring disputes over oil and other matters.

But in Turkey and Iran, bloody clashes between government forces and Kurdish militant groups are not uncommon.

Erdogan has been concerned about the rise in political power among the Kurds in his country, where they secured a sizable faction in Ankara's parliament in the last election.

And he has frequently complained about armed Kurdish separatists seeking harbor and support in neighboring countries, prompting Turkey to start building a wall on the border with Iran as well as its borders with Iraq and Syria this year.

Erdogan has also sharply criticized U.S. efforts to arm and organize Kurds in neighboring Syria to fight the Islamic State group, saying those weapons might be turned against Turkish forces

The talks between Erdogan and Baqeri over the Kurdish referendum, the war in Syria, and other issues lasted 50 minutes,Turkey's state-run Anadolu news agency said.

On Syria, Baqeri said afterward that the two regional powers were seeking "coordination for creating peace and security," IRNA reported.

It represented the latest effort by Tehran and Ankara to overcome differences in Syria, where Iran has been a strong ally of Syrian President Bashar al-Assad in his country's six-year civil war and Turkey has supported armed Sunni Arab groups fighting to oust Assad.

Turkey's effort to coordinate more with Tehran mirrors its efforts to cooperate more with Russia in Syria. Moscow also backs the Assad government.

The three countries have sponsored Syrian peace talks in the Kazakh capital of Astana this year, which have recently focused on trying to create "de-escalation zones" to limit the bloodshed in Syria.

Aside from their differences over Syria, relations between overwhelmingly Sunni Muslim Turkey, a secular state, and the mainly Shi'ite Islamic Republic of Iran have on occasion been tense over the years.

Erdogan has sometimes lashed out at the rise of "Persian nationalism" and the power of Shi'ite militias in Iraq.

But Iran and Turkey have a common enemy as well, with the emergence of the Islamic State (IS) extremists in Iraq and Syria in 2014. IS has staged devastating attacks in both countries and recently has become increasingly active at recruiting in Iran.

AFP reported that a senior official from Iran's Islamic Revolutionary Guard Corps said Baqeri's visit to Ankara was prompted by the presence of "terrorist groups" in the border area, without saying which ones.

"We are seeking a good agreement with Turkey to provide better security for Iranian and Turkish borders especially in the west and northwest," Guards spokesman General Ramezan Sharif was quoted as saying by IRNA.

With reporting by AFP and Reuters