The president and his national security advisers contemplated striking Iran but backed away as costs loomed and Mideast allies lobbied for restraint.