ISTANBUL — Just two months ago, many in the West thought President Recep Tayyip Erdogan of Turkey could be shifting away from what they considered his overly close relationship with President Vladimir V. Putin of Russia.
Mr. Erdogan had a warm meeting with President Biden. Turkey allowed a group of celebrated Ukrainian commanders, being held in the country as part of a prisoner exchange deal, to return to the battlefield, angering Russia. And Mr. Erdogan dropped his resistance to allowing Sweden to join NATO, strengthening the military alliance’s efforts to isolate Russia.
But there was no signal of a major change in Mr. Erdogan’s balancing act between Russia and the West on Monday, when he and Mr. Putin stood side by side in the Russian resort city of Sochi and spoke of further expanding their countries’ partnership. They would increase trade and work together on energy issues, they said, despite efforts by Mr. Erdogan’s NATO allies to cripple Russia’s economy and limit its access to global energy markets.
They also discussed a more pressing geopolitical topic — the resumption of an agreement to allow the export of Ukrainian grain through the Black Sea — although they announced no concrete progress.
The leaders’ joint appearance made clear that their relationship endures and will likely continue to develop, largely because both sides have more to gain from the partnership than they stand to lose, analysts said.
As Russia finds itself ostracized from the West, Turkey has served as a vital channel, declining to join Western sanctions and continuing to ship much needed goods to Russia. For Turkey, struggling with an economic crisis, Russia has proved a fertile market for Turkish exports and has bolstered the Turkish government’s finances with delayed gas payments and deposits in Turkey’s central bank.
“As far as Erdogan is concerned, he is, in my opinion, living in the best of both worlds,” said Ahmet Kasim Han, a professor of international relations at Beykoz University in Istanbul.
The Turkish leader has managed to take steps to please his NATO allies, like agreeing to admit Sweden to NATO and meeting with Mr. Biden, without jeopardizing the many perks of his relationship with Mr. Putin.
Mr. Putin also benefits from his open channel with the leader of a NATO country, Mr. Han said, because it gives him an indirect way to communicate his views to the rest of the alliance, sometimes to the frustration of other members.
“If I were in the Kremlin, I would prefer a member of the alliance that sometimes hinders and delays issues that are of tactical importance to the members,” Mr. Han said. “It is nice to have a nuisance like that among your rivals.”
Since Russia invaded Ukraine 18 months ago, deciphering the relationship between Mr. Putin and Mr. Erdogan has been an evolving puzzle for Western policymakers as they navigate the complex diplomacy surrounding the war.
For the West, Mr. Putin is the conflict’s villain, and the United States and other NATO members have sought to hobble his war machine with sanctions.
Mr. Erdogan staked out a more complex position, condemning Russia’s invasion and offering aid to Ukraine while expanding his country’s economic ties with Russia and referring to Mr. Putin as “my friend.”
That approach gave Mr. Erdogan a unique diplomatic role, allowing Turkey to help broker prisoner exchanges and the grain deal, which he and others have credited with facilitating food deliveries to poor countries. But his refusal to shun Mr. Putin frustrated NATO allies and led some policymakers to privately question which side he was on.
This summer seemed to offer indications that Mr. Erdogan wanted warmer ties with his NATO allies. During his meeting with Mr. Biden, Mr. Erdogan spoke of “a new process” with the United States. Mr. Erdogan welcomed President Volodymyr Zelensky of Ukraine to Turkey and said that Ukraine “deserves NATO membership with no doubt,” a position that is anathema to Russia.
But on Monday, it was clear how entwined Russia and Turkey have become.
Mr. Putin noted how much trade between Russia and Turkey had increased in recent years. He mentioned Turkey’s status as a go-to destination for Russian tourists who now struggle to travel elsewhere in Europe. About five million Russians visited Turkey last year, Mr. Putin said.
The two countries increasingly cooperate on energy issues, and plan to do so more in the future. Last winter, Moscow allowed Mr. Erdogan to delay payments for Russian gas and permitted the Turkish government to make some payments in currency other than dollars, easing pressure on Turkey’s reserves.
For his part, Mr. Erdogan spoke proudly of a nuclear power plant that Russia is building near the Mediterranean coast in Turkey and expressed interest in a second one.
Alexander Gabuev, director of the Carnegie Russia Eurasia Center, said the leaders also likely discussed other issues.
Both countries’ delegations included their central bank chiefs, suggesting talks about conducting more trade in their national currencies, Mr. Gabuev said. He also noted the attendance of Dmitri Shugayev, director of the Russian Federal Service for Military-Technical Cooperation, meaning that military matters were also likely discussed.
“There is the underwater part of the iceberg, which we don’t know,” Mr. Gabuev said.
Despite their talk of increased cooperation, the two leaders failed to restore the Black Sea grain deal, which had been brokered by Turkey and the United Nations last year. Russia withdrew in July, saying that it had not received the benefits expected from the arrangement.
Turkey and Russia have previously discussed establishing a gas hub in Turkey. The idea appeals to Mr. Erdogan as a way to improve Turkey’s weak position in global energy markets, and it could allow Russia to sell its gas to countries that would not buy it directly.
Mr. Putin said on Monday that the Russian state energy giant Gazprom had given a “road map” for the project to its Turkish counterpart, BOTAS.
Energy experts, however, have questioned the viability of Mr. Putin’s proposal, saying it seemed unlikely that the European Union would approve new Russian gas conduits or seek to increase supplies to Europe.
Europe has put considerable effort into reducing its reliance on Russian gas imports and finding alternative sources like liquefied natural gas shipments from the United States, Qatar and elsewhere.
Ben Hubbard reported from Istanbul and Paul Sonne from Berlin. Reporting was contributed bySafak Timur from Istanbul, Stanley Reed from London and Marc Santora from Odesa, Ukraine.