KABUL—Iran has allowed the Taliban to open an office in eastern Iran and discussed providing them with surface-to-air missiles, ramping up the potential for cooperation with the insurgents, according to senior Afghan and Western officials.

Iran's shift came after the U.S. and Afghanistan sealed a long-term partnership agreement in May, and in an effort to expand its options for retaliation should its nuclear facilities be attacked, the officials said.

Iran,...