(CNN) -- President Obama lauded the U.S. military in Baghdad on Tuesday during an unannounced visit to Iraq, reminding troops that the next 18 months will be difficult as the United States plans to start withdrawing its forces.
President Obama greets troops during a visit to Camp Victory on Tuesday.
"I was just discussing this with your commander, but I think it's something that all of you know. It is time for us to transition to the Iraqis," Obama said, according to a transcript from the White House. "They need to take responsibility for their country and for their sovereignty.
"And in order for them to do that, they have got to make political accommodations. They're going to have to decide that they want to resolve their differences through constitutional means and legal means. They are going to have to focus on providing government services that encourage confidence among their citizens."
Obama reiterated that Iraqis must do those things themselves, and "we can't do it for them."
"But what we can do is make sure that we are a stalwart partner, that we are working alongside them, that we are committed to their success," he added. Watch Obama thank the troops »
Obama said that in terms of training the Iraqi security forces, the U.S. must make sure "they know that they have a steady partner with us."
Obama's visit to Iraq was the last stop on his first trip overseas as president.
The president thanked the troops for giving Iraq "the opportunity to stand on its own as a democratic country." Read the transcript
The president addressed about 1,500 service members, civilians and contractors who gathered in the rotunda of the Al Faw Palace, one of dozens of palaces that were used by former Iraqi leader Saddam Hussein. The palace is now headquarters for the Multi-National Corps.
Obama last month announced the United States' plan to withdraw most of its troops from Iraq by the end of August 2010. A residual force of between 35,000 to 50,000 troops will remain until December 31, 2011. There are 142,000 American troops in Iraq now.
Gen. Ray Odierno, the top U.S. commander in Iraq, met Obama shortly after Air Force One landed Tuesday in Baghdad at about 4:42 p.m.
The troops "are doing extraordinary work," Obama said shortly after landing. "They're just putting their heart and soul into this."
About 600 troops assembled to greet the president at Camp Victory, near the Baghdad airport.
Yassin Majid, the spokesman for Iraqi Prime Minister Nuri al-Maliki, said Obama met with the prime minister, and they discussed bilateral relations and other issues. Obama also was to meet with Iraqi President Jalal Talabani and the nation's two vice presidents.
Ali Jalal, a businessman, called Obama's visit "a good sign to Iraqi people, and will solve the political crisis."
"If God wills, he [Obama] should know that Iraq belongs to Iraqis," Jalal said, then added, "I ask the U.S. President Barack Obama to solve the problems of Iraqi people and to speed up the withdrawal of U.S. troops."
Government employee Nazar Sami-a said, "His visit is for Americans' interest and not for Iraqi interest."
Obama arrived in Europe last week for a series of summits, initially meeting with world leaders at the G-20 summit in London, England, to discuss the global financial crisis.
At the NATO summit in France and Germany, the president was hoping to get a boost in resources for the war in Afghanistan. He did get allies to pledge about 5,000 troops, but in the form of police and security trainers, not combat troops.
During the campaign season, Obama visited Iraq on a multi-stop overseas trip. That trip also included stops in Afghanistan, Jordan, Israel, Germany, France and the United Kingdom.
A new CNN/Opinion Research Corporation poll found that 79 percent of Americans surveyed feel that Obama has had a "more positive" effect on how people in other countries view the United States. Only 19 percent of those surveyed thought he's had a "more negative" effect.
The poll also indicated that only 35 percent of Americans currently approve of the U.S. war in Iraq; 65 percent disapprove.
Almost seven in 10 Americans agree with Obama's plan to remove most U.S. troops from Iraq by next August, while leaving a residual force of between 35,000 and 50,000 troops.
CNN's Ed Henry and Mohammed Tawfeeq contributed to this report.