Earlier he met with Gen. Ray Odierno, the top U.S. army commander in Iraq, at the airport and then drove to Camp Victory.
Obama told Odierno he came to thank the American troops for their "extraordinary work" and said there is "nothing better than getting a face to face" meeting.
The president was expected to hand out 10 Medals of Valor.
Odierno told Obama that even with recent bombings, the number of incidents in Iraq are at their lowest since the war began.
The president's stopover was marked by the rise in violence that Odierno mentioned to Obama.
In the capital, a car bomb killed nine people and wounded 20 in the Shiite neighborhood of Kadhimiya. The blast came one day after a series of explosions ripped through the city killing more than 30 people.
And in Fallujah, a suicide bomber detonated a car bomb at a police checkpoint, killing one policeman.
This was Obama's first visit to a war zone as president and his third trip to Iraq.
Last July, at the height of the general election, Obama traveled to Afghanistan and Iraq and met with U.S. commanders and troops there as part of a congressional delegation.
Obama visited Iraq one previous time, in January 2006.
Today's visit was made in complete secrecy because of security concerns. The White House gave no advanced details of the trip and his arrival in Iraq was not made public until he had landed at Baghdad's airport.
White House press secretary Robert Gibbs told reporters traveling on Air Force One that the decision was made to travel to Iraq instead of Afghanistan for three key reasons: first, Iraq's proximity to Turkey, where he was today; second, the need to consult with Iraqi officials on the political situation there; and third, to visit with U.S. troops.
There are currently 139,000 U.S. troops in Iraq. Under the president's withdrawal plan, by September those numbers will be reduced by 12,000 troops.
Odierno has said he will assess at that time whether the security climate will allow the drawdown of an additional combat brigade by year's end. Odierno wants to maintain the bulk of his forces in place for December's national election.
After that, U.S. troops levels will be reduced by the end of August 2010 to the 35,000 to 50,000 that will remain in Iraq as a training force.
The Status of Forces Agreement between the U.S. and Iraq calls for all American troops to be out of Iraq by the end of 2011.
The president talked a great deal about Iraq while in Turkey the last two days, noting that tensions between the U.S. and the majority Muslim nation broke out after Turkey refused to let the U.S. -- a fellow NATO member -- bring troops through that country at the start of the Iraq war.
Obama currently is trying to get Turkey to allow Amercian troops entry into Turkey on their way out of Iraq.
Earlier today Obama told a group of Turkish university students that he opposed the war in Iraq because he thought it was a "bad idea," but now he is responsible for bringing troops home in a way that does not result in "a complete collapse into violence."
"So some people might say, wait, I thought you were opposed to the war, why don't you just get them all out right away? Well, just because I was opposed at the outset it doesn't mean that I don't have now responsibilities to make sure that we do things in a responsible fashion," Obama said in Istanbul.