Pakistan's political chaos has dominated the headlines in past weeks amid concern over what David Miliband labelled as Islamabad's "mortal threat". The United States is taking matters into its own hands with the Obama administration even considering launching strikes deep within Pakistan's territories.

What has slipped from the headlines of concern in London and Washington is that Pakistan's chaos has been reverberating somewhere else, namely Iran, its eastern neighbour, which remains itself the subject of international anxiety.

Pakistan's chaos has not only raised concern in Tehran's Islamic government; it has reshuffled Iran's foreign policy, through weakening ideologues who stress the need to forge better ties with the Islamic world, and further strengthening the pragmatists' relentless search for new alliances to preserve security and territorial integrity.

Pragmatists or realpolitik advocates are gaining ground since Iran's rapprochement with Pakistan failed both to halt the rise of the Taliban in Afghanistan, and to counter the mounting extremism inside Pakistan's Sunni majority, along with sectarian tensions and violence. Among the violence's most distressing episodes were the killings of Iranian diplomats and citizens inside Pakistan, incidents that followed the then Pakistan-backed Taliban's August 1998 killings of seven Iranian diplomats in Mazar-i-Sharif in northern Afghanistan.

Just a few months before the Mazar-i-Sharif attack, Iran had taken an ideological stance towards India's nuclear tests, siding with "Pakistan, our brother", according to Iranian official statements. Mohammad Khatami, Iran's reformist president, told Pakistan's then prime minister, Nawaz Sharif, that "we regard your security seriously and understand your position and the position of our brother, the Pakistani nation. The security of Pakistan, as a brother, friendly and neighbouring state, is crucial to us".

Another ailment of the "brotherly" rapprochement was the 2004 declaration of Iran and Pakistan's two border regions, Baluchistan and Sistan-Baluchestan, "twin provinces"; it has stopped short of weakening the sectarian-separatist violence in the region, in particular the fundamentalist Jundullah group's explosions and beheadings of Iranian soldiers. Jundullah, Arabic for soldiers of Allah, has been launching attacks from its bases in the lawless Pakistani province of Baluchistan.

The call for strengthening ties with the Islamic world to replace the severing and deteriorating ties with the west has always been put down by challenges to security and territorial integrity, starting with Iraq's invasion of Iran in 1980. This too has driven Iranian foreign policy towards more pragmatism, gradually abandoning the pillars of its Islamic Republic's foreign policy, in particular the export of its revolution.

Since Iran engaged in direct confrontation with the United States in the Persian Gulf where oil interests necessitate a direct involvement, Central Asia provided more space for a contest between the Islamic Republic's two disparate foreign policy approaches.

However, and partly due to Iran's relations to Russia, pragmatism dominated its foreign policy in the former Soviet republics. For instance, Iran tilted to Armenia in its long-standing territorial dispute and war with Azerbaijan, a country that not only shares Islamic faith with Tehran, but also has a majority Shia population, similar to Iran. In Tajikistan, another Muslim state, Tehran refrained from siding with Islamic fundamentalists in the country's civil war (1992-7), defying once more its early revolutionary aims.

Despite the Sunni-Shia divide, Iran's relations with Pakistan embarked on a different course. Tehran rapprochement with Pakistan in the 90s served the remaining ideologues' "Muslim brotherly relations" approach, in spite of Islamabad's strong relations with the United States and Saudi Arabia. It remained one of the ideologues' last bastions, providing in theory a model of Muslim "brotherly" relations as foreseen in fundamentalist utopias.

Nevertheless, the series of events that unfolded after the Taliban's rise to power dictated a distinctive strategy to the dislike of Iran's ideologues. After the killings of its diplomats in Afghanistan and Pakistan, Tehran allied itself with Islamabad's arch enemy, New Delhi, for both nations now face a similar threat, Sunni extremism. The New Delhi declaration signed between Iran's president and India's prime minister in January 2003 called on both sides to broaden their "strategic collaboration in third countries", in a clear reference to Afghanistan.

Iran also co-operated with the United States during the Afghanistan invasion in October 2001 and in its aftermath, specifically in forging the post-war power-sharing deal in the Bonn conference.

The re-emergence of the Sunni extremist threat in Baluchistan, a province whose population mostly belongs to the Sunni sect, has alarmed even the Iranian regime's hard-line elements. After the beheading of 13 Revolutionary Guards in 2007, Ahmad Khatami, one of Iran's leading hard-line clerics, accused Pakistan of turning into a "sanctuary for terrorists", warning that "although Pakistan is our neighbour; little by little it is losing its neighbourly manners. Pakistan has become a sanctuary of terrorists who kill people in Zahedan", Sistan-Baluchestan's provincial capital. The cross border attacks have piled pressure on the leadership amid calls to deploy the Revolutionary Guards within Pakistan's lawless territory.

After its victory in 1998, both the Taliban's continuous threats and the subsequent chaos in Pakistan, compelled Iran to strengthen its ties with India and later co-operate with the United States, its utmost adversary, against the new regime in Afghanistan.

Today, the re-emergence of the same threats to Tehran's security and territorial integrity might pave the way for yet another phase of co-operation over Afghanistan, albeit this time in the presence of an American administration inclined towards dialogue and co-operation.