Iran is one of a handful of countries to make clear they are not shutting the door on the government being formed by the Taliban.
It comes amid global fears over the future of Afghanistan under the militants, underlined by the chaotic removal of diplomats and at-risk Afghans from Kabul airport.
While other countries are closing embassies and reassessing relations, Iran, along with Russia, China and Pakistan, said it would maintain its diplomatic presence in Afghanistan. Iran's embassy in Kabul and its consulate in Herat, on its eastern border, remain “fully open and operational”, Foreign Ministry spokesman Saeed Khatibzadeh said.
Iran’s response to the swift fall of President Ashraf Ghani's western-backed government and the Taliban takeover is not a surprise, said Sanam Vakil, a senior research fellow at Chatham House.
“Tehran has been preparing for the reality of the Taliban with pragmatism by negotiating with the group to protect its interests, its border, its economic interests that have been important to combat sanctions pressure and to protect the targeting of Shia groups," Ms Vakil told The National.
This pragmatism should not be misread, Ms Vakil said. There is no love lost between Iran and the Taliban. In fact, most Iranians fear the Taliban's radicalism.
In 1998, two years after seizing power for the first time, the Taliban killed 11 diplomats and a journalist in Tehran's mission in Mazar-i-Sharif. Iran responded by moving 10,000 troops to the Afghan border in addition to the 70,000 already there.
Iran's support for the 2001 US-led invasion of Afghanistan is said to have been a key element in the toppling of the Taliban regime and to have ushered in the presidency of Hamid Karzai. Iran supported the training of the Afghan army. One prominent Afghan leader told the RAND think tank that "if it weren’t for Iran, our western friends would not be able to come today so easily and tell us about all the things they have done for us”.
The Iranian stance was partly to ensure its security and partly to support an initiative by then president Mohammad Khatami to open dialogue with the West. It also coincided with the US and Iran's shared interest in preventing narcotics production, border insecurity and the flow of refugees from Afghanistan. But this changed with US president George W Bush's rejection of these overtures, in which he branded Iran part of an "axis of evil", and the combative, anti-west policies adopted by Mr Khatami's successor, Mahmoud Ahmadinejad.
Afshon Ostovar, associate chairman for the research department of national security affairs at The Naval Postgraduate School in California, said Iran had pursued a "multifaceted strategy" which included both working with the post-2001 Afghan government and helping the Taliban insurgency against US forces.
"Today, the Taliban and Iran have a good working relationship. They're not partners or allies, but they did have a shared interest regarding ending the US military presence in Afghanistan,” Mr Ostovar told The National.
Just a few weeks prior to the Taliban takeover, Iran's president, Ebrahim Raisi, made it clear that Tehran expected the foreign, meaning American, presence in the region to end. He called the US decision to withdraw its troops from Afghanistan “an opportunity to restore life, security, and lasting peace in that country”.
Iran’s outgoing foreign minister, Mohammad Javad Zarif, even hosted the Taliban in Tehran in July this year for a meeting with envoys of the US-backed Kabul government.
But while Iran wants the US out of Afghanistan, it is also keen that its eastern neighbour remains stable.
“Iran wants to prevent Afghanistan from becoming a pillar of US influence in the region," Mr Ostovar said.
"Beyond that, Iran would of course like a measure of security and stability in Afghanistan so that trade can continue unimpeded, and a refugee crisis be avoided. Those goals are currently contradictory, and how Iran's approach to Afghanistan might evolve with the transition to Taliban rule is yet to be seen.”
For now, Tehran seems to be "cautiously optimistic", he said.