Although he did not support the war in Iraq and has announced plans for an accelerated pullout from Iraq, the president has gone to great lengths to show that he supports the troops. With the backdrop of a giant American flag hung from the marble balconies, Obama told US troops they had accomplished something extraordinary.

"It is time for us to transition to the Iraqis," he told the troops. "It is time for them to take responsibility for their country," he said, adding that the next 18 months would be crucial.

The base, which is the headquarters of the US ground operations in Iraq, was named Camp Victory – a word President Obama does not use in relation to the Iraq war. Close to Baghdad's International Airport, it is technically outside the city, which means that US troops can remain there after the pullout from Iraqi cities this June mandated in the standard of forces agreement with Iraq.

For his part, Prime Minister Nouri al-Maliki set aside traditional protocol to go see the US president, who normally would have taken a helicopter into the Green Zone inside Baghdad to meet with his Iraqi hosts. The White House said sand storms prevented helicopters, which had been scheduled to take the president to meet with Mr. Maliki and President Jalal Talabani, from making the six-minute trip in the poor visibility.

In the past two days, more than 40 people have been killed in seven separate bombings and sparked Iraqi fears that violence could be on the rise again. US officials dismiss it as a blip rather than a trend. 4,265 American troops have been killed in Iraq since 2003 while tens of thousands of Iraqis have lost their lives in the war.

Maliki was pictured in an official photo meeting with Obama on the US base, under a painting of the Iraqi marshes and between the American and Iraqi flags. He assured the president that "all the progress made in the security area will continue." Obama urged him to continue with political reconciliation in government and security forces, including with Sunni Iraqis, an apparent reference to the Sons of Iraq, a largely Sunni paramilitary group credited with helping defeat Al Qaeda in Iraq. The US recently handed over the group to Iraqi control.

Obama was expected to speak with Mr. Talabani by phone, US officials said.

Warm welcome from troops

There has been a deep strain of mistrust of Obama in parts of the traditionally conservative US military. Graffiti on some military bases still occasionally compares him to Osama bin Laden, echoing a smear campaign based on anti-Islam sentiment during the presidential campaign. Obama is Christian but his father was Muslim.

But at Camp Victory on Tuesday, the troops gave their commander-in-chief a riotous welcome, with some of the female service members reaching out to hug him.

It was Obama's first visit to Iraq as president; he was last here in 2008 as a presidential candidate. Iraq was his last stop on an eight-day tour to Europe and Turkey, in which he sought to repair relations with America's allies.

On President Bush's last trip to Iraq in December, before he left office, an Iraqi journalist made headlines around the world by hurling his shoes at the president's head. Just hours before President Obama arrived, in a coincidence of timing, Iraq's Supreme Court reduced Muntadhar al-Zeidi's time in prison to one year in jail, from the three he was sentenced to earlier this year.