In a landmark visit to Turkey by Iran's president, the two countries pledged to work together to stop extremism and bloodshed in the Middle East despite deep differences over Syria's civil war.
"Iran and Turkey, the two important countries in the region, are determined to fight against extremism and terrorism," Iran's President Hasan Rouhani told a news conference in Ankara, adding that neither country benefited from instability in the neighbourhood.
Turkish President Abdullah Gul commended Rouhani on his efforts in opening up Iran to the world since taking office last August.
But the diplomatic niceties papered over a relationship that remains complex and often dysfunctional, with the two sides locked in an increasingly bitter competition for influence between Sunni and Shia Muslim powers in the Middle East.
The biggest division has come over the Syrian civil war, in which they have found themselves supporting opposing sides.
Iran, a Shia theocracy, is the chief backer of Syrian President Bashar al-Assad, while Sunni-majority Turkey has moved from trying to encourage reform in Syria to overtly supporting the armed opposition.
Rouhani has congratulated Assad on his re-election for a third seven-year term last week, in a poll ridiculed by Syrian opposition groups and their Western and Arab backers.
"What is important for us is to stop the bloodshed and conflict in Syria, remove terrorists coming from various countries and to let the people of Syria decide on its future," he said on Monday.
Turkey, meanwhile, blasted the elections as "null and void", saying that it was "out of the question to take them seriously".
The Syrian poll "represents a clear contradiction to the Geneva declaration seeking a political solution," a Turkish foreign ministry official told AFP.
- Iran sees 'turning point' -
Rouhani's trip to Turkey, flanked by a crowded delegation of ministers and Iranian businessmen, saw 10 bilateral deals signed in several sectors including finance, tourism, culture and communications -- part of efforts to more than double trade to $30 billion (22 billion euros) by 2015.
The Iranian president later met with Prime Minister Recep Tayyip Erdogan, who said: "We have made progress in our relations since Rouhani's election."
Iran and Turkey also chaired the first meeting of a high-level cooperation council, a new mechanism they have established to promote trade and regional integration.
Rouhani said the visit "will undoubtedly be a turning point in the two countries' relationship".
Signup to our newsletter and follow us on Facebook and Twitter!
It was the first trip to Turkey by an Iranian president since former leader Mahmoud Ahmadinejad made a "working" visit to Istanbul in 2008. The last official presidential visit from Iran to Turkey was in 1996 by Hashemi Rafsanjani.
That visit was marked by controversy when Rafsanjani refused to visit the mausoleum of modern Turkey's revered founder Mustafa Kemal Ataturk -- a routine practice for foreign heads of state. Rouhani also skipped the mausoleum.
Ataturk's secular credentials make him an unpopular figure with Iran's theocratic rulers.
- Complex relationship -
Despite the tensions, both countries have many reasons to work together.
Both are concerned about the rise of sectarian conflicts on their borders, and most of all wish to maintain their close energy and trade ties that have been threatened by Western sanctions targeting Iran.
Turkey is heavily reliant on Iran for oil and gas, having few energy resources of its own. It has been a fierce opponent of Western sanctions that has severely curtailed its access to Iranian fuel in recent years.
Ankara has been accused of circumventing the sanctions by quietly trading gold for Iranian gas.
Turkish prosecutors are currently investigating what they describe as a huge criminal network that used bribes and payoffs to conceal the illicit trade.
Erdogan has dismissed the allegations as a foreign plot and put huge pressure on investigators to drop the case. His government hopes a deal between Iran and the West will see the sanctions dropped permanently.
Ankara has long defended Tehran's right to peaceful nuclear technology but adamantly opposes any development of nuclear weapons, which it fears would lead to an arms race in the Middle East.
"We don't want any country in our region to possess nuclear weapons. We maintain our desire for a Middle East cleared of weapons of mass destruction," Gul said on Monday.
"Our region should be cleared of not only nuclear but also conventional weapons," added Rouhani.
Yet Iran and Turkey have emerged as competitors for influence across the Middle East -- notably in Iraq and Syria -- as well as in Central Asia and the Caucasus.
Even on areas where they might be inclined to cooperate -- such as in the fight against Kurdish separatism -- they have often sought to undermine each other.
Both Turkey and Iran face a threat from Kurdish rebels who wish to break away and form their own country. But instead of working together, each government have sponsored rebels in the other's backyard over the years.