ERBIL, Iraq—President Barack Obamasignaled the likelihood of an enduring U.S. military involvement in Iraq, but said airstrikes and other aid would only help contain the threat from Sunni extremists until the country's leaders form a new government to confront the crisis.

The latest offensive by the militant group Islamic State over the past week brought the fighters to within 25 miles of the capital of the semiautonomous Kurdish region, Erbil. The U.S. conducted three rounds of airstrikes on Friday aimed at halting further moves toward the city, where American military advisers and diplomats are stationed.