MAKHMOUR, Iraq—The struggles of the embattled Kurdish Peshmerga to repel Islamist insurgents have put the U.S. and Iran on the same side, with both rushing to reinforce a revered fighting force to defeat a common enemy.

U.S. airstrikes this week helped the Peshmerga retake two towns on the outskirts of Erbil that they had lost days earlier in a stunning defeat that put the radical Sunni group Islamic State 20 miles from the capital of the semiautonomous Kurdish region.

...