US President Barack Obama has said the time has come for Iraqis to "take responsibility for their country".
Mr Obama was speaking during an unannounced trip to Baghdad, his first visit to the country as president.
He was greeted enthusiastically by US troops, whom he praised for their "extraordinary achievements" in Iraq.
Mr Obama also had talks with Iraq's leaders, and confirmed his plans to withdraw all US troops from Iraq by the end of 2011.
The president flew into Baghdad's international airport before travelling by road to meet Gen Ray Odierno, the US military commander in Iraq, and some of the 140,000 US soldiers serving in the country.
Mr Obama thanked Gen Odierno for helping to lead what he said was "a very effective operation" in Iraq.
He told about 600 US soldiers gathered at the Camp Victory military base that they had helped Iraq to "stand on its own as a democratic country".
"That is an extraordinary achievement, and for that you have the thanks of the American people," he said.
The troops had greeted him with cheers and shouts of "we love you Obama".