Recent media reports that Iran is arming and funding the Afghan Taliban came as a surprise to many, not least of all because Iran’s Shi'ite clerical regime almost went to war with the hard-line Sunni Taliban in 1998.
Tehran confirmed that a delegation headed by the Taliban's political point man held discussions with senior Iranian officials in May. But it has rejected claims that the Afghan insurgents have established a "shura," or leadership council, in the northeastern Iranian city of Mashad or receive arms and money from Tehran.
Looking at Iran's murky regional dealings, it is clear that Iran has backed many hard-line Sunnis -- some of whom later turned on their former sponsors.
Most Afghans believe that Tehran harbored Gulbudin Hektmatyar, one of the most radical Afghan Islamists, for years before the 9/11 attacks in New York and Washington in 2001. Later, Tehran did little to prevent him from moving to Pakistan to orchestrate attacks against the new Western-backed Afghan government.
A new bestseller on Islamic State (IS) militants has documented allegations of Tehran's covert support for Abu Musab Al-Zarqawi. Before his killing in a U.S. airstrike in 2006, Al-Zarqawi lead Al-Qaeda's deadly branch in Iraq. Ironically, the enterprise he founded has now evolved into the IS -- Iran's deadly foe.
Tehran now appears to be undertaking a great gamble with the Afghan Taliban. The timing of its support for the Taliban is puzzling and comes at a critical juncture. Kabul is working hard to mend relations with Islamabad, which has traditionally been the Taliban's main foreign backer.
In financing the Taliban, Iran's strategy appears to be three-fold. First, Iran has a huge stake in keeping a friendly regime in Kabul because Iran and Afghanistan share a border and are deeply intertwined geo-politically and culturally.
Believing that the Taliban are key players in any outcome of the ongoing conflict in Afghanistan, Tehran has swiftly decided to make friends with a potent adversary that it can influence when required. But Iran doesn't want a complete return of a hostile regime across its eastern border, which is why it wants to keep the Taliban in check.
Secondly, Iran's key goal in reaching out to the Taliban now is to stop IS militants from establishing themselves along its border. IS has formed an Afghanistan-Pakistan branch in recent months and is actively pushing for a further foothold in the region.
IS is hell bent on the destruction of Iran. Its affiliates in Afghanistan have also waged war on the Taliban, thus making the alliance a classic case of "the enemy of my enemy is my friend."
In light of this heightening security threat, hard-liners in Tehran believe they must take calculated risks by financing the Taliban to mitigate the growth of IS inside Afghanistan, fearing an eventual IS attack on Iran.
Finally, Iran is gearing up for a U.S. and NATO withdrawal from Afghanistan. With billions of dollars in cash expected to be made available from sanctions relief as part of the nuclear deal with the U.S., Tehran can spare funds to bankroll a buffer force against enemy groups.
In case the U.S. decides to stay longer than the current timeline, Tehran will have enough leverage to keep American forces busy and protect Iranian interests--a strategy it believes succeeded in neighboring Iraq.
Iran watchers say the general consensus in Tehran is that building a force from scratch is expensive; it requires training and know-how that existing groups can bring without much ado.
Unlike Iraq, however, the Afghans welcomed foreign forces and want the U.S. to maintain a military presence beyond the current deadline. This prompts Tehran to support armed Afghan proxies because it sees Washington's long-term military presence as part of a plan to encircle Iran.
Such calculations are based on shaky grounds. In supporting the Taliban, Tehran is inadvertently risking its own security. Critics believe that Tehran has adopted Pakistan's strategy of advancing its interests through proxy wars.
But decades of covert and overt support for the Taliban have failed to win Islamabad any true friends or influence in Afghanistan. Instead, Islamabad is facing the wrath of extremists in the shape of Tehrik-e Taliban Pakistan (TTP) -- its homegrown terror group and a general blowback towards its myopic policies.
As a Shi'a majority country, Iran is more vulnerable to such repercussions. Its largest and most underdeveloped southeastern Sistan-Baluchistan province has a Sunni majority and its ethnic Baluch communities maintain strong cross border links with Pakistan and Afghanistan. The region has been suffering from attacks by small Baluch Sunni rebel factions. Under the Taliban's patronage, these groups can morph into Iranian versions of the TTP.
In an indication of its desperation, the Afghan Taliban recently launched an online fundraising appeal.
What guarantees can Tehran possibly have to ensure that their Afghan clients won't double cross them?
The Iranians also risk locking horns with American forces. Tehran supported Shi'a forces in Baghdad in order to frustrate American efforts to reconcile various competing factions and secure Iraq. Tehran pressured former Iraqi Prime Minister Nouri al-Maliki to refrain from signing a Status of Forces Agreement with Washington allowing U.S. troops to stay. Iran's machinations wreaked havoc and contributed to the creation of IS, which now controls large swaths of Syria and Iraq.
Most significantly, Afghanistan's premier intelligence agency, the National Directorate of Security (NDS), will be forced to explore forming a covert alliance with Tehran's enemies if Kabul feels threatened by Iranian support for the Taliban.
Tehran's dangerous flirtation with the Taliban is ultimately destined to end in a lose-lose situation for both the Taliban and Iran's Shi'ite regime.
Atta Nasib is a political commentator on Afghan affairs. These views are the author's alone and do not represent those of Radio Free Europe/Radio Liberty.