Defense Secretary Robert Gates on Tuesday warned that a political stalemate and sectarian violence could mar Iraq’s future. 

“I am not saying that all is, or necessarily will be, well in Iraq,” Gates said at the 92nd American Legion National Convention in Milwaukee, Wis.

Gates’s remarks came just hours before President Obama was scheduled to mark the end of combat operations in Iraq with a speech to the nation from the Oval Office. 

“This is not a time for premature victory parades or self-congratulation even as we reflect with pride on what our troops and their Iraqi partners have accomplished,” Gates said. 

About 50,000 U.S. troops will remain in Iraq through next year to train and support the Iraqi military and police. They will also assist with counterterrorism operations. 

Gates noted that the chance for “political freedom” in Iraq has been “purchased at a terrible cost.” The Iraqi people have endured loss of life and trauma, he said, and 4,427 U.S. service members have died during the course of Operation Iraqi Freedom. Another 34,265 U.S. service members have been wounded or injured.

The defense secretary credited the U.S. troop surge in 2007 with securing the country and making the change of mission possible. But he also said the war in Iraq shifted attention and resources away from Afghanistan, allowing the Taliban to regroup there. 

Gates acknowledged that the public has grown impatient about the “pace of progress” in Afghanistan, but stressed that the “full complement” of the additional troops ordered by Obama is just now arriving. 

Gates said that he believes the United States has the “right strategy” in Afghanistan — one that “represents our best chance of achieving goals essential to the safety of the United States.” 

"Success there is not inevitable," Gates said. "But with the right strategy and a willingness to see it through, it is possible. And it is worth the fight.”