Vladimir Putin’s criminal war against Ukraine promises to have long-term negative consequences. But if there’s a faint trace of a silver lining in the storm Putin has unleashed, it’s the renewal of Turkey’s relationship with the U.S. and NATO.

For individuals and nations alike, times of crisis have a way of putting things in perspective. That appears to be what’s happening for Turkey and NATO.

The longtime NATO member has been estranged from the alliance due to Turkish president Recep Tayyip Erdogan’s authoritarian tendencies at home and wayward actions abroad.

Early in Erdogan’s rise to national prominence, many observers worried about his commitment to liberal democracy—i.e., majority rule with minority rights, the rule of law, political pluralism, religious tolerance. While serving as Istanbul mayor in the 1990s, for example, Erdogan was arrested for fomenting hatred after reciting these words: “The mosques are our barracks, the domes our helmets, the minarets our bayonets and the faithful our soldiers.” It was an early indication of his bent toward Islamist governance. This dangerous fusion of religion and politics is something the modern state of Turkey opposed from its post-World War I founding and enshrined in its post-Ottoman constitution, which embraced secularism and republicanism.

By 2010, Erdogan’s party was using brute political force to weaken the judiciary and shut down newspapers. As the Politico notes, Erdogan had taken “a dark turn toward authoritarianism”—and a dramatic turn away from the U.S. and NATO, as Erdogan defiantly began leaning toward Putin and Tehran.

Erdogan’s actions led elements of the Turkish military to attempt a coup in 2016, which he used as a pretext to purge Turkey’s institutions of anyone daring to deviate from his cult of personality. He closed media outlets; seized control of NGOs and colleges; fired 6,000 judges, prosecutors and 40 percent of Turkey’s generals; and detained or suspended 60,000 government employees. He then staged a rally with a million people waving banners that read, “You are a gift from God, Erdogan.”

As to Erdogan’s actions abroad, the most troublesome have been his moves against Kurdish rebel groups in Syria/Iraq and his 2017 decision to purchase and deploy—over Washington’s strong objection—Russia’s S-400 air-defense system.

The effect of Erdogan’s moves against the Kurds was to weaken and scatter the West’s strongest partners on the ground in the fight against ISIS.

As a consequence of Erdogan’s S-400 decision, Washington threw Turkey out of the F-35 consortium—a select group of U.S. allies invited to participate in the production and deployment of one of the world’s most sophisticated stealth fighter-bombers. Understandably, Washington worried that the S-400 system—and its Russian trainers and technicians—would be able to tap into the F-35’s technology.

Washington was not only livid with Erdogan, but concerned about his drift into Putin’s orbit. Erdogan was equally furious with Washington.

Yet Russia’s rampage through Ukraine has reminded these old allies that they have a common enemy and common interests. That’s what brought them together—and held them together—during the Cold War. Indeed, it pays to recall that NATO and Turkey overcame internal challenges during the Cold War that were more serious than recent post-Cold War challenges. Consider the Anglo-French deceptions during the Suez crisis in 1956; military coups in Turkey in 1960, 1971 and 1980; open military hostilities between fellow NATO members Greece and Turkey in the 1970s and 1980s; France’s decision to throw out NATO’s headquarters and pull out of NATO’s integrated military command structure in 1966-67; France and Germany waging a diplomatic war against the U.S. and Britain over Iraq’s repeated violations of UN Security Council resolutions in 2002-03.

Now, as during the Cold War, shared interests and shared dangers represented by threats from Moscow are pulling Turkey and the rest of NATO back together.

As Putin tries to reconstitute the Russian Empire, Erdogan is realizing, finally, that Turkey’s future is far better served by its alliance with NATO—which has stood by Turkey for seven decades—than by a marriage of convenience with Russia—which is an ancient foe of the Turkish people, a serial violator of treaties, and now an international pariah.

Turkey has shown itself to be firmly on the side of Ukraine’s sovereignty and democracy. Erdogan visited Kiev in February for defense talks, shipped ground-attack drones to Ukraine (which have been lethally effective against Putin’s invasion forces), allowed Kiev to begin producing Turkish-designed drones, joined NATO’s other 29 members in roundly rejecting Putin’s outrageous December diktat, and served as one of Ukraine’s emissaries to Moscow. Ukrainian president Volodymyr Zelensky has leaned on Erdogan throughout the crisis. Erdogan has called Putin’s invasion “a clear violation of Ukraine's political unity, sovereignty and territorial integrity” and “unacceptable.” And most dramatic of all, for just the second time in history, Turkey closed the Black Sea to Russian warships. Under the Montreux Convention, Ankara is empowered to determine the movement of military vessels through the straits connecting the Black Sea and Mediterranean Sea.

Beyond Ukraine, Turkey has openly and forcefully challenged Moscow’s military operations in Syria and Libya (where those Turkish drones also targeted and eliminated Russian weapons.)

As Turkey comes in from the cold, it seems likely that Erdogan will give up Russia’s S-400s, which would allow Turkey to rejoin the F-35 partnership. It’s also likely that Turkey will be key in resupplying Ukrainian troops and militia and in reinforcing NATO allies near Ukraine. Pentagon and State Department officials have made clear that the U.S. plans to continue supplying Ukraine weapons via overland and Black Sea routes. Turkey will be essential to this effort.

Given its strategic location, its membership in NATO and its contributions to U.S. security interests over the decades, Turkey represents one of those tough tests for Washington in trying to balance interests and ideals.

President Ronald Reagan mastered at finding that balance. It begins with keeping an eye on the big picture. For Reagan, the big picture was defeating Soviet communism. Thus, Reagan backed pro-democracy and anti-communist movements (the latter were not always democratic) in Poland, Afghanistan, Africa and Central America; supported the Philippines, South Korea and Spain as they transitioned to democracy; and stood by Turkey through times of internal and external trouble.

Today, the big picture enfolds deterring Putin, supporting Ukrainian freedom-fighters and defending NATO. If Turkey is willing to help the U.S. achieve those objectives, it should be considered an ally—an imperfect but important one.

None of this is to countenance or forgive Erdogan’s authoritarian moves at home. But with Russia on the march, NATO and Turkey need each other—in Europe, the Black Sea and the Mediterranean Sea—just as they did during the Cold War.