An Iraqi reporter called the visiting US president George Bush a "dog" and threw his shoes at him during a news conference in Baghdad today.

Iraqi security officers and US secret service agents leapt at the man and dragged him struggling and screaming out of the room where Bush was giving a news conference with Iraqi prime minister Nuri al-Maliki.

The shoes missed their target by about 15 feet (4.5m) away. One sailed over Bush's head as he stood next to Maliki and smacked into the wall behind him. Bush smiled uncomfortably and Maliki looked strained.

"It doesn't bother me," Bush said, urging everyone to calm down as a ruckus broke out in the conference room.

When asked about the incident shortly after, Bush made light of it. "I didn't feel the least threatened by it," he said.

The White House said the surprise visit — his first to Iraq since September 2007 — was designed to thank the troops, highlight a drop in violence and formally sign a new security pact with the Iraqi government. With less than six weeks to go before the end of Bush's presidency, he will be looking to present the pact, the so-called status of forces agreement, as a sign that the ill-fated US occupation of Iraq has turned a corner.

"The work hasn't been easy, but it has been necessary for American security, Iraqi hope and world peace," Bush said of the five-and-a-half-year occupation. "I'm just so grateful I had the chance to come back to Iraq before my presidency ends."

The security pact, approved by the Iraqi parliament three weeks ago, provides for the removal of US troops from Iraqi cities by the middle of next year and a full withdrawal by 2011. But there are already signs that the agreement is running into problems. Most importantly, its timetable will have to be squared with that of the incoming president.

Barack Obama has said consistently that he will pull US forces out of Iraq within the much tighter timeframe of 16 months, security conditions permitting. He is likely to highlight that ambition early on in his term, which begins on January 20.

The provision to evacuate US personnel from Iraqi cities by mid-2009 has also been drawn in to question. Over the weekend the top US commander in the country, General Ray Odierno, said American troops would remain in several cities beyond next summer, acting in a support role as part of "transition teams".

Doubt has also been cast on the legal basis of the new pact, which leaves the US occupation without the cover of a UN mandate.

Bush flew into Baghdad on Air Force One after an 11-hour flight shrouded in secrecy. He began the trip with talks with the president, Jalal Talabani, and his aides. "I've known these men for a long time and I've come to admire them for their courage and their determination to succeed," Bush said.

Though violence levels last month fell to their lowest since the war began in 2003, bombings remain common. More than 4,209 US personnel have died in the conflict, according to the Associated Press, with 149,000 remaining in the country.

In recent days, Bush has expressed his regret about the intelligence debacle over claimed Iraqi weapons of mass destruction, but he has also insisted that the increased presence of US troops in the past year has transformed the country. He has said:"There were legitimate differences of opinion about the initial decision to remove Saddam Hussein, and the subsequent conduct of the war. But now the surge and the courage of brave Iraqis have turned the situation around."