WASHINGTON — For two years, President Obama has boasted that he accomplished what his predecessor had not. “I ended the war in Iraq,” he has told audience after audience. But a resurgence by Islamic militants in western Iraq has reminded the world that the war is anything but over.

What Mr. Obama ended was the United States military presence in Iraq, but the fighting did not stop when the last troops left in 2011; it simply stopped being a daily concern for most Americans. While attention shifted elsewhere, the war raged on and has now escalated to its most violent phase since the depths of the occupation.

The turn of events in a country that once dominated the American agenda underscores the approach of a president determined to keep the United States out of what he sees as the quagmires of the last decade. In places like Afghanistan, Egypt, Libya and Syria, Mr. Obama has opted for selective engagement and accepted that sometimes there will be bad results, but in his view not as bad as if the United States immersed itself more assertively in other people’s problems.

The president’s methods have come under new scrutiny in recent days with flags of Al Qaeda hoisted over Falluja and Ramadi, two names with deep resonance for a generation of American veterans who spilled blood there. And the criticism was fueled by a new memoir by former Defense Secretary Robert M. Gates describing an ambivalent commander in chief who did not believe in his own military buildup in Afghanistan and wanted mainly to get out of Iraq.