The security agreement gives the president and the Republican Party a foreign policy win heading into the midterm elections.