WASHINGTON—As the U.S. struggled in recent years to help prop up Afghanistan’s anemic economy, the American military turned for help to an unlikely partner: Iran.

The U.S. has no formal relations with Tehran and American companies are restricted from working with Iran by sanctions over the country’s disputed nuclear activities. Nevertheless, a specialized Pentagon task force sought to engage Afghanistan’s western neighbor for major business ventures it was promoting in the country.

Twice in the last two years, the task force secured special permission from the U.S. government to seek help from Iran in setting up Afghanistan’s first pharmaceutical company and in developing four mines, according to government documents reviewed by The Wall Street Journal and interviews with people directly involved in the unusual outreach effort.

(Latest:Obama wrote secret letter to Iran’s Khamenei about fighting Islamic State).

Though the engagement with Iran ultimately faltered, the efforts demonstrated the lengths to which the American military was willing to go to promote business investment in Afghanistan to replace billions of dollars the U.S. and its allies have spent during 13 years of war.