BEIRUT, Lebanon — Just weeks ago, President Recep Tayyip Erdogan of Turkey dropped his objections to allowing Finland and Sweden to join NATO — a move that angered President Vladimir V. Putin of Russia.
Now he is off to Iran for talks with none other than Mr. Putin himself, with President Ebrahim Raisi also in attendance.
The trip highlights Mr. Erdogan’s complicated and often apparently contradictory statecraft. As a member of NATO, Turkey is supposedly allied with pro-Europe Ukraine. And a leading Turkish drone manufacturer is proudly selling drones that Ukrainian forces have used to blow up Russian tanks.
But still, Mr. Erdogan has gotten closer to Mr. Putin in recent years and has kept lines to the Russian leader open, serving as a mediator between him and President Volodymyr Zelensky of Ukraine and pushing for talks aimed at allowing grain from Ukraine to pass Russia’s blockade to ease global food shortages.
Throughout his tenure at the helm of the Turkish state, Mr. Erdogan has used a complex web of relationships with several countries to make Turkey a player, serving as a go-between for nations in conflict or playing foes off one another for his own benefit.
While NATO’s other members may view Turkey as a sometimes problematic member of the alliance, its membership gives Turkey added weight when dealing with countries like Russia and Iran. Conversely, Mr. Erdogan uses his wide array of outside relationships for leverage against NATO, said Karabekir Akkoyunlu, a lecturer in Middle East politics the School of Oriental and African Studies at the University of London.
“This is part balancing, maneuvering, double game,” Mr. Akkoyunlu said. “You can put a positive spin or a negative spin on it, but that’s been the sort of trademark of Erdogan’s foreign policy.”
Despite Turkey’s differences with Russia over Ukraine, the countries have other issues to discuss in Iran.
All of the countries are militarily active in the war in Syria, for example, albeit on different sides. Russia and Iran both came to the aid of President Bashar al-Assad, while Turkey supported the rebels seeking to oust him and now controls a large swath of territory inside Syria along the Turkish border, and wants to take more.
Mr. Erdogan has been talking for months about launching a new military incursion into northeastern Syria to flush out Kurdish militiamen whom Turkey considers terrorists. But Russia also has troops in the area, so the operation is unlikely to go ahead unless Turkey can work it out with Russia.
Turkey also maintains ties with Iran, even though Turkey, as a member of NATO, is part of the U.S.-led Western alliance that Iran opposes. That means that while the United States is looking for partners to deter Iran in the Middle East, Mr. Erdogan does not hesitate to accept the country’s hospitality.
Mr. Putin is only the latest visitor to Iran from Moscow. Russia is seeking hundreds of armed and unarmed surveillance drones from Iran to use in the war in Ukraine, and a Russian delegation visited an airfield in central Iran at least twice in the last five weeks to examine drones that can be armed, according to the White House.
Alper Coskun, a former Turkish diplomat and a senior fellow at the Carnegie Endowment for International Peace, said Turkey’s location meant it had to “maintain a balance as a country in the region.”
“It is natural and right for Turkey to keep close relations with Russia and Iran in order to protect national interests, while also fulfilling NATO membership duties,” he said, noting that some Western countries found these contacts disconcerting.
“Since our Western allies, particularly the U.S., have some concerns on whether Turkey shares the collective interests, these bilateral contacts may raise eyebrows,” he said.