A newly released trove of documents the U.S. found in the compound where Osama bin Laden was killed provides new insights into al Qaeda’s relationship with Iran, suggesting a pragmatic alliance that emerged out of shared hatred of the U.S. and Saudi Arabia.

After the U.S. toppled the Taliban regime in Afghanistan in 2001, members of al Qaeda, which was based there, scrambled to escape. Most of them crossed the border into Pakistan. But others moved to Iran, an al Qaeda official who appeared to be a senior member of the militant...