He said he had come to Iraq for face-to-face meetings and to get a better sense of the security situation, and to thank US troops for their "extraordinary work".
"General Odierno has been helping to lead a very effective operation here," he said, referring to General Ray Odierno, the top US commander in Iraq.
'Time for transition'
Addressing US troops stationed at Camp Victory, Obama said: "You have given Iraq the opportunity to stand on its own as a democratic country. That is an extraordinary achievement."
He told soldiers that it was "time for us to transition to the Iraqis".
"They need to take responsibility for their country," he said.
Obama has already announced plans to withdraw most US combat troops from Iraq on a 19-month timetable.
Despite this, US troops will provide security for the Iraqi elections and as many as 50,000 troops are expected to remain in the country at the end of the 19 months.
Obama was received with cheers from the troops many of whom took his picture on digital cameras.
"I love you," someone in the crowd shouted out, at one point, to which Obama replied: "I love you back."
Obama also met Nuri al-Maliki, the Iraqi prime minister.
Following their meeting, Obama said he had "strongly encouraged" the Iraqi leader to take steps to unite political factions, including integrating Sunnis into the government and security forces.
Tuesday's trip was Obama's third visit to Iraq and his first since taking office.
Obama's trip comes at the conclusion of his European tour, which had officially ended with two days in Turkey, his first visit to a Muslim nation as president, where he told Turks that the US is not "at war" with Islam.
|Obama was given a warm reception by US
combat troops in Iraq [Reuters]
"Let me say this as clearly as I can: the United States is not, and will never be, at war with Islam ... if we are joined together in delivering that message East and West, to the world, I think we can have an extraordinary impact," he said in an address to the Turkish parliament.
He also called for a greater partnership with the Muslim world.
Later, speaking in an address to a number of Turkish students in Istanbul, Obama said peace in the Middle East was possible, but called for Israelis and Palestinians to offer concessions.
His trip to Turkey also drew protests by demonstrators who said Obama was seeking to press Turkey to deploy troops in Afghanistan in an effort to control the situation there.