U.S. President Barack Obama made a surprise trip to Iraq Tuesday, telling American troops that it is time for Iraqis "to take responsibility for their country," and thanking soldiers for the sacrifices they have made during six years of fighting.

Obama was making his first visit to Iraq as commander-in-chief and was met by hundreds of cheering soldiers at Camp Victory, the primary American military base in Iraq.

"You have given Iraq the opportunity to stand on its own as a democratic country," Obama told the troops. "That is an extraordinary achievement."

More than 4,200 American soldiers have been killed in Iraq since the military operation began in March 2003. Obama plans to end combat operations in the country by the end of 2010.

"It is time for us to transition to the Iraqis," he said. "They need to take responsibility for their country."

Obama also spoke with Iraqi Prime Minister Nouri al-Maliki, who said after the meeting that he "assured the president that all progress that has been made in the security area will continue."

For his part, Obama said he "strongly encouraged" al-Maliki to work toward uniting the country's various political factions, such as including Sunni Muslims in the government and security forces.

Obama landed in Baghdad on the last leg of his overseas trip, which included economic and NATO summits in Europe and a two-day trip to Turkey.

Obama has been to Iraq twice before, including last summer during his campaign for the presidency.

ABC's Yunji De Nies, reporting from Istanbul, told Â鶹´«Ã½net Tuesday that Obama had the choice to visit either Iraq or Afghanistan.

White House press secretary Robert Gibbs said Obama chose Iraq for the following three reasons:

  • Iraq's close proximity to Turkey
  • to meet with soldiers who are serving under him
  • the need to consult with Iraqi officials personally

Obama's surprise visit included a heavy security detail, which shielded him from the moment he stepped off of Air Force One.

Just hours before Obama arrived, a car bomb exploded in a Shiite neighbourhood of Baghdad.

After greeting Gen. Ray Odierno, the top commander of U.S. troops in Iraq, Obama stepped into a waiting SUV for the ride to Camp Victory. Troops lined the motorcade route, standing at attention.

Speaking to soldiers inside a marble palace, Obama was interrupted several times by cheering soldiers.

"I love you," someone in the crowd yelled. "I love you back," Obama replied.

Obama had planned to travel by helicopter to the heavily fortified Green Zone, but the trip was cancelled due to poor weather conditions.

In Turkey, Obama discussed the long-standing opposition to the war in Iraq.

However, he said that the troop withdrawal must be done "in a careful enough way that we don't see a collapse into violence."

Obama has announced plans to withdraw most combat troops from Iraq within a 19-month timetable.

At the end of the period, as many as 50,000 troops are expected to remain in Iraq to perform counterterrorism duties.

With files from The Associated Press