The U.S. definitely tries to play both sides of the conflict as Iran and the Taliban clash. Pakistan surely feels threatened and intervenes against the Iranians, creating a major regional war that NATO might eventually have to sort out a la the Bosnian War in the early 1990s.
I'm not entirely sure it would come to that.
Pakistan skirted entirely clear of igniting a major war with the Soviet Union during the near-decade of the Soviet war in Afghanistan. If anything, they would probably just revert to strong levels of covert (and occasionally boldly direct) support of the Afghans against the Iranians, and play a waiting game of drawing the Iranians into the Afghan meatgrinder and waiting for attrition and endless guerrilla warfare to take its toll. The US in all likelihood will back up Pakistan from day one, and it will have likely almost unilateral diplomatic support from the rest of the world in its support of the "courageous Taliban warriors" defending their people who are being once again butchered by a cackling foreign tyrant. This is a great situation for Pakistan, they hold all the cards, and Afghanistan likely moves even further to being a Pakistani client-state.
It will probably be the final nail in the coffin for Iran's diplomatic reputation as well.
As the Lovetts (Going to Teheran) have pointed out, Iran in the late 90s was keeping a low profile under Khatami and trying to normalize relations with the US, even going so far as to suspend work on it's nuclear program. The US was not interested and turned out to be more interested in Union Oil's proposal to build an oil and gas pipeline from Turkmenistan to Karachi via the Taleban's Afghanistan. The US has been biased in favor of Sunni regimes ever since FDR for whatever reason.
Besides, Iran had few allies in 1998 and Iran's border with Pakistan is open desert with few natural defenses. Pakistan's army and air force are larer and moe advanced than Iran's to say nothing of Pakistan's nuclear weapons.
NOW if the Taleban attack the Shia Hazari once the US is out of Afghanistan, Iran may get directly involved with helping the Hazari and attack the Taleban now that Russia is backing Iran. The taboo against recognizing a seceded state is a lot less and Russia could get away with recognizing a seceded Hazara state. Or a second Tajik or an Aimak state.
It bears mentioning that this alleged bias towards Sunni Muslim states (the vast majority of the Muslim world is Sunni, it would be like accusing the United States of favoring Roman Catholicism by pursuing good relations with countries in Latin America) didn't seem to prevent the US from forging a very strategic and very lucrative set of agreements with the pre-revolutionary Iranian government, and now that it's independent, the Azeri government, both of which are Shia-majority states (and the only such states in the entire world with the addition of Bahrain, though that will not last if the Al-Khalifas are successful with their artificial demographic shift schemes).
Also, the Iranians cannot simply invade through Sistan & Balochistan, a province that combined with its significantly large Pakistani equivalent is the site of one of the longest-running insurgencies in the Greater Middle East/Central Asia. The Baloch don't have that much reason to play nice with the Iranian occupiers (quite the contrary, they'll likely realize that Tehran's rule will be just as strict, if not more so, than Islamabad's). And in any case, Iran would be knowingly invading a large, highly-militarized state that just detonated its first nuclear weapon (or would do so within the year, depending on the timeframe), and a state that over twice as many people as Iran at that.
The Iranian leadership were and are not stupid people, their game is an extremely calculating one, and avoiding regional blowups like this one has been a consistent policy of theirs. If somehow Iran's hand were forced in Afghanistan, it would be their game to lose once the Pakistanis got involved. A nuclear-armed state with a massive, modernized military stocked up on US-built equipment and over two times as many people as their opponents is pretty much guaranteed to have at least a respectable win, if not a total victory.