Troops in Baghdad Cheer President Obama's Surprise Visit

President Obama swooped into Baghdad under a cloak of secrecy today, but his presence quickly turned into a raucous meeting with several hundred U.S. troops who cheered wildly when he told them it is time for Iraqis to take responsibility for their country.

By the time Air Force One was "wheels up" four hours later, the president has consulted with his top commander in Iraq, the president and prime minister of Iraq, and shook hands with dozens of delighted American soldiers who tried to photograph their commander-in-chief with cell phones.

At one point Obama's motorcade was flanked by a cordon of U.S. troops five deep, standing at attention and saluting.

Video of Barack Obama addressing troops in Iraq during a surprise visit.Play

"It was wonderful seeing those troops out there," Obama said.

In a brief address that was part pep talk and part pat on the back, Obama said that the next 18 months will be a "critical period" in Iraq, referring to the August 2010 deadline for the withdrawal of all U.S. combat forces from Iraq.

"You have given Iraq the opportunity 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," Obama told about 700 U.S. service members, including Vice President Biden's son Beau, at Camp Victory the sprawling American camping that is a short car drive from Baghdad airport.

"You will be critical in terms of us being able to make sure Iraq is stable, that it is not a safe haven for terrorists, and we can start bringing our folks home," Obama said at the Al Faw Palace, a former palace for Saddam Hussein.

Obama got one of his biggest cheers when he told the troops it is time for the Iraqis to step up and take over.

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

Obama told the troops he understood how difficult the tours overseas have been on their families back home and said he and his wife Michelle are working to provide additional resources.

"We have not forgotten what you have done, grateful for what you will do and as long as I'm in White House you will get support you need and the thanks you deserve," he said, citing increases in his budget for military families.

Obama received a raucous welcome from the troops gathered at the palace. Many held up digital cameras above their head to try and snap a picture of the president on the stage. Someone in the crowd shouted, "I love you," to which the president replied, "I love you back."

Obama said he would keep his remarks short in order to shake as many hands as possible, and after he finished speaking, he worked the ropeline, greeting the troops.

The president made the surprise detour on his way home from his European trip, stopping in Baghdad today to meet with U.S. commanders and consult with Iraqi officials.

Obama said there has been "significant political progress" in Iraq but noted there is still "a lot of work to be done."

After a 30 minute meeting with Iraqi Prime Minister Nouri al-Maliki, Obama stood with the prime minister and said the U.S. is committed to an orderly transition from American to Iraqi forces and said the planned drawdown will ultimately result in the removal of all U.S. troops by 2011. He also had a sit-down with Iraqi President Jalal Talabani.

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.

Obama Goes From Turkey to Iraq

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.

Obama's opposition to the war in Iraq was a critical part of his campaign for the presidency. In a speech in October 2002 Obama stated his opposition to the war in Iraq and said while he did not oppose "all wars" he did oppose "dumb wars."

The Baghdad stop wrapped up the president's first overseas trip which aides declared to be "enormously productive."

Obama ended his trip with cultural events and a town hall meeting in Istanbul, Turkey, with about 100 Turkish university students.

As he has done several times before on this trip, Obama spoke to the students about change and looked toward the future, promising a "new chapter in American engagement" with the rest of the world.

Building New Ties to World Leaders

"When people come together and speak to one another and share a common experience, than their common humanity is revealed," the president said. "When that happens, mistrust begins to fade and our smaller differences no longer overshadow the things that we share."

Senior Obama adviser David Axelrod declared the trip to be "enormously productive," both in terms of substance and building relationships with world leaders and their populations.

The accomplishments on the trip that Axelrod highlighted include securing the commitment of G-20 nations for greater regulation of financial institutions, support among NATO nations for the president's Afghanistan strategy and building a number of stronger relationships with foreign leaders.

"Throughout the campaign, the president spoke about the need to repair our relationships in the world, to mend our frayed alliances and begin again a dialogue with our allies and discussions with our adversaries to try to move America's agenda forward, to try to make our country safer, to set the conditions for a better future," Axelrod said. "We feel that we've taken a great step forward on this trip."

Axelrod said the president had the opportunity to establish personal relationships with many leaders who will prove to be key to "promoting America's interest in the world and the world's security in the future."

White House aides believe that Obama's popularity abroad will make it easier for world leaders to cooperate with the United States.

Axelrod joked that some seeking to gauge the success of the trip seem to be asking, "'Why didn't the waters part, the sun shine and all the ills of the world disappear because President Obama came to Europe this week?' That wasn't our expectation," he said. "That will take at least a few weeks."

Obama Gets Pat on Back for Basketball Picks

Earlier this morning, Obama met with Christian, Muslim and Jewish religious leaders, including Grand Mufti of Istanbul professor Mustafa Çagrici, Chief Rabbi Isak Haleva and Syrian Orthodox Archbishop Yusuf Cetin.

Obama talked more than religion and politics during a separate meeting with Ecumenical Patriarch Bartholomew I, the archbishop of Constantinople, according to a White House aide. After detailing a long list of items accomplished by Obama on this trip, including his speech to the Turkish Parliament Monday, Ecumenical Patriarch Bartholomew I threw in a little hoops talk.

"Oh, and by the way, congratulations on North Carolina," the archbishop said, referring to Obama's successful pick of the Tar Heels to win the NCAA college basketball tournament Monday night in Detroit.

The president, according to the White House aide, laughed and smiled.

Obama later took a tour of the Hagia Sofia Basilica with Turkish Prime Minister Tayyip Erdogan. Obama called the site "spectacular." In keeping with Muslim tradition, Obama took off his shoes to visit the Blue Mosque, Istanbul's most famous landmark

ABC News' Luis Martinez contributed to this report